各位老师 大神们帮我看看VBA运行那里出了错误?
大家看看我这个VBA那个地方错了,不管输入什么数字都显示的是120种
Sub ouyangff()
s = 2
Application.ScreenUpdating = False
For i = 1 To 5
For j = 1 To 5
For k = 1 To 5
For l = 1 To 5
For m = 1 To 5
If i <> j And i <> k And i <> l And i <> m And i <> k And j <> k And j <> l And j <> m And k <> l And k <> m And l <> m Then
Cells(s, 2) = Cells(i, 1)
Cells(s, 3) = Cells(j, 1)
Cells(s, 4) = Cells(k, 1)
Cells(s, 5) = Cells(l, 1)
Cells(s, 6) = Cells(m, 1)
s = s + 1
End If
Next
Next
Next
Next
Next
Application.ScreenUpdating = True
End Sub
看粗体,第一个2表示从B列开始,否则覆盖了A2的数据;第2个明显你把行、列搞反了。
另外奉送你Application.screenupdating这两句话,速度快5倍以上哦
帮忙看看vb这个程序里哪错了
For i = 5 To 2 //改为For i = 5 To 2 step -1
VB程序谁帮我看看哪里错了
数组排序,稍微改了一下,没有错误了:
Dim a(1 To 10) As Integer
Private Sub Command1_Click()
Load Form1
End Sub
Private Sub Command2_Click()
p = ""
For i = 1 To 9
For j = 1 To 10 - i
If a(j) < a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next
Next
For i = 1 To 10
p = p & Str(a(i)) & ","
Next
Label2.Caption = LTrim(Left(p, Len(p) - 1))
End Sub
Private Sub Form_Load()
Dim p As String
Randomize
p = ""
For i = 1 To 10
Do
x = Int(Rnd * 91) + 10
yes = 0
For j = 1 To i - 1
If x = a(j) Then yes = 1: Exit For
Next
Loop While yes = 1
a(i) = x
p = p & Str(a(i)) & ","
Next
Label1.Caption = LTrim(Left(p, Len(p) - 1))
Label2.Caption = ""
End Sub
Excel VBA出现错误‘9,跪求大神帮忙!
下标越界是因为“arr(i - 1)”引起的:
引用数组里的值时,必须使用二维引用的方式,即arr(i-1)是错误的,必须使用arr(i-1,1)的格式。