你好,VBA 怎样给长度为变量的数组赋值,你知道吗?比如下面的程序,如何用数组编写? 能帮忙就太感谢了!
PrivateSubqq()DimiAsingeter,jAsingeter,nAsingetern=20000Fori=2TonStep1Forj=1Ton-iStep...
Private Sub qq()
Dim i As ingeter, j As ingeter, n As ingeter
n=20000
For i = 2 To n Step 1
For j = 1 To n - i Step 1
If Cells(i, 3) = Cells(i + j, 3) And Cells(i, 3) <> "" Then
Cells(i, 4) = Cells(i, 4) + Cells(i + j, 4)
Cells(i + j, 2) = ""
Cells(i + j, 3) = ""
Cells(i + j, 4) = ""
End If
Next j
Next i
End Sub
'我没多少分了,只能给你10分了! 展开
Dim i As ingeter, j As ingeter, n As ingeter
n=20000
For i = 2 To n Step 1
For j = 1 To n - i Step 1
If Cells(i, 3) = Cells(i + j, 3) And Cells(i, 3) <> "" Then
Cells(i, 4) = Cells(i, 4) + Cells(i + j, 4)
Cells(i + j, 2) = ""
Cells(i + j, 3) = ""
Cells(i + j, 4) = ""
End If
Next j
Next i
End Sub
'我没多少分了,只能给你10分了! 展开
1个回答
展开全部
数组的长度可以用变量表示,比如下面代码,就可以先定义一个动态数组,然后根据一个算式来确定数组的大小,再给它赋值
Sub abc()
Dim a() As Integer
n = 0
'写入动态数组
x = 3 * 4
ReDim a(0 To x) '根据表达式计算X的值来确定数组大小
For i = 1 To 3
For j = 2 To 5
a(n) = i + j: n = n + 1
Next
Next
'从动态数组取数
For i = 0 To n
Cells(i + 1, 1) = a(i)
Next
End Sub
Sub abc()
Dim a() As Integer
n = 0
'写入动态数组
x = 3 * 4
ReDim a(0 To x) '根据表达式计算X的值来确定数组大小
For i = 1 To 3
For j = 2 To 5
a(n) = i + j: n = n + 1
Next
Next
'从动态数组取数
For i = 0 To n
Cells(i + 1, 1) = a(i)
Next
End Sub
来自:求助得到的回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询