vba给数组赋值'向VBA数组中写⼊数据
'1、按编号(标)写⼊和读取
Sub t1() '写⼊⼀维数组
Dim x As Integer
Dim arr(1 To 10)
arr(2) = 190
arr(10) = 5
End Sub
Sub t2() '向⼆维数组写⼊数据和读取
Dim x As Integer, y As Integer
Dim arr(1 To 5, 1 To 4)
For x = 1 To 5
For y = 1 To 4
arr(x, y) = Cells(x, y)
Next y
Next x
MsgBox arr(3, 1)
End Sub
'2、动态数组
Sub t3()
Dim arr()
Dim row
row = Sheets("sheet2").Range("a65536").End(xlUp).row - 1
ReDim arr(1 To row)
For x = 1 To row
arr(x) = Cells(x, 1)
Next x
Stop
End Sub
'3、批量写⼊
Sub t4() '由常量数组导⼊
Dim arr
arr = Array(1, 2, 3, "a")
怎么给数组赋值
Stop
End Sub
Sub t5() '由单元格区域导⼊
Dim arr
arr = Range("a1:d5")
Stop
End Sub

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。