繁体   English   中英

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

[英]Copy Cells values from Excel sheet into an array

我有一个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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM