2015-12-21 33 views
0

我有一个Excel工作表abc.xlsm”和我有值‘A1’到‘在这片A15’我要复制至第10行,然后存储所有的。使用VBA数组值复制单元格的值从Excel工作表到一个数组

+0

欢迎的话,请提出问题,当更具体一点:你尝试过什么,你能指望什么,等等。参见[如何提问](http://stackoverflow.com /帮助/如何对问) – Nehal

回答

0

正如在评论中提到的,请在您的问题更具体:大多数的问题应该有至少你尝试了哪些代码一些位无论如何这应该工作,具有。对额外的概念:

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 
相关问题