weixin_38166612
weixin_38166612
2017-04-04 15:44

急!!!求助VBA大神帮我看一下我的代码运行不了。

30
  • vba

各位大神,我是VBA入门级菜鸟,我就是想从913条数据中随机选取其中60%,并复制到另外一张Sheet里。请大神帮我看一下为什么我的代码运行不成。系统提示,问题出在
n = Sheet2.Cells(n, "A").Value
这一行上。这是我的屏幕截屏,谢谢帮忙
下面是我自己的代码:

Option Explicit

Sub Random60()

Dim RndNumber, n, i, j, k, m, temp(547), Maxrec As Integer

n = Sheet2.Cells(n, "A").Value

Randomize (Timer)

Maxrec = 912

k = 0

Do While k < Maxrec * 0.6

RndNumber = Int((Maxrec * Rnd) + 1)

temp(k) = RndNumber

For i = 0 To k - 1

If temp(i) = RndNumber Then Exit For

Next i

If i = k Then k = i + 1

Loop

For n = 1 To 912

If n = RndNumber Then

Sheet2.Rows(n).CopySheet4.Rows (k + 1)

Next

End Sub

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答