将单元格值从Excel工作表复制到数组中

将单元格值从Excel工作表复制到数组中,excel,vba,Excel,Vba,我有一张Excel表格“abc.xlsm”,我的值在“A1”到“A15”之间“在这张纸上。我想复制到第10行,然后使用VBA将所有值存储在一个数组中。如评论中所述,请在您的问题中更具体一些:大多数问题至少应该有一些您尝试过的代码。无论如何,这应该是可行的,还有几个额外的概念: Sub copy() 'Declaring an array - if you know the data type you can type is as well Dim varray As Variant 'Decla

我有一张Excel表格“abc.xlsm”,我的值在“A1”到“A15”之间“在这张纸上。我想复制到第10行,然后使用VBA将所有值存储在一个数组中。

如评论中所述,请在您的问题中更具体一些:大多数问题至少应该有一些您尝试过的代码。无论如何,这应该是可行的,还有几个额外的概念:

Sub copy()
'Declaring an array - if you know the data type you can type is as well
Dim varray As Variant
'Declaring other variables - don't need to be separeted, just for clarity
Dim i As Long, iLenghtArray As Integer, rgData As Range, rgTarget As Range

'This is to dimension your array - you have tell VBA the lenght of it, or use REDIM
ilengtharray = 10

'Setting the range reference
Set rgData = Sheet1.Range("$A$1:$J$1")

'Then set the array = to the range you set above
varray = rgData

'Then you can interate over your array like so:
For i = 1 To UBound(varray, 2)
    Debug.Print varray(1, i)
Next

'You can also directly past your array into a suitable range
'Setting destination range:
Set rgTarget = Sheet1.Range("$A$2:$J$2")
rgTarget = varray

End Sub

欢迎来到SO,请在提问时更具体一点:您尝试了什么,您期望什么,等等。请看