vba數(shù)組怎么賦值給單元格區(qū)域

vba
小億
1062
2023-09-16 19:16:27
欄目: 編程語言

要將VBA數(shù)組賦值給單元格區(qū)域,可以使用Range對(duì)象的Value屬性。以下是一個(gè)示例代碼:

Sub AssignArrayToRange()
Dim arr(1 To 3, 1 To 3) As Integer
Dim rng As Range
'給數(shù)組賦值
arr(1, 1) = 1
arr(1, 2) = 2
arr(1, 3) = 3
arr(2, 1) = 4
arr(2, 2) = 5
arr(2, 3) = 6
arr(3, 1) = 7
arr(3, 2) = 8
arr(3, 3) = 9
'將數(shù)組賦值給單元格區(qū)域
Set rng = Range("A1:C3")
rng.Value = arr
End Sub

在這個(gè)示例中,我們創(chuàng)建了一個(gè)3x3的整數(shù)數(shù)組arr,并賦值。然后,我們使用Range對(duì)象rng來指定要賦值的單元格區(qū)域(A1:C3),并使用Value屬性將數(shù)組賦值給該區(qū)域。

1