创建和VBA移调阵列 [英] Creating and Transposing Array in VBA
问题描述
我希望在一个范围内的负载值到一个数组和移调阵列到另一个位置(不同的工作簿)
我使用的是下面的论坛上发帖来获取如何做到这一点的想法:
<一个href=\"http://www.mrexcel.com/forum/excel-questions/629320-application-transpose-visual-basic-applications-array.html\" rel=\"nofollow\">http://www.mrexcel.com/forum/excel-questions/629320-application-transpose-visual-basic-applications-array.html
下面是code我与现在的工作,而且我得到了1004对象定义错误。任何人都可以发现什么,我做错了什么?
我也发现,code工作,如果我不设置tRangeArray,而是做表(工作表Sheet1)的范围。(C12:C19).value的= Application.Transpose(MYARRAY )
,但我不知道为什么这是从我的code不同。
子copy_data()
昏暗CRANGE由于品种齐全,人气指数为范围,tRange1作为范围,wbk1作为工作簿,wbk2作为
工作簿
昏暗MYARRAY()作为变,tRangeArray作为范围设置wbk1 =的ThisWorkbookMYARRAY =范围(E12:L12)
设置tRangeArray = wbk1.Sheets(工作表Sheet1)的范围。(C12:C19)表(工作表Sheet1)。范围(tRangeArray).value的= Application.Transpose(MYARRAY)
正如我在评论中提到的,只需使用:
tRangeArray.Value = Application.Transpose(MYARRAY)
表(工作表Sheet1)。范围(tRangeArray).value的
不工作,因为范围
可以接受单参数 - 字符串范围的地址的(而不是范围本身):范围(地址)
,无论是两个参数 - 左上角和右下角单元格:范围(cell_1,cell_2)
I'm hoping to load values in a range to an array and transpose that array to another location (different workbook)
I am using the below forum post to get an idea of how to do it:
Below is the code I am working with now, and I'm getting the 1004 object defined error. Can anyone spot what I am doing wrong?
I did find that the code works if I do not Set tRangeArray and instead do Sheets("sheet1").Range("C12:C19).Value = Application.Transpose(MyArray)
, but I'm not sure why that's different from my code.
Sub copy_data()
Dim cRange As Range, aRange As Range, tRange1 As Range, wbk1 As Workbook, wbk2 As
Workbook
Dim MyArray() As Variant, tRangeArray As Range
Set wbk1 = ThisWorkbook
MyArray = Range("E12:L12")
Set tRangeArray = wbk1.Sheets("sheet1").Range("C12:C19")
Sheets("sheet1").Range(tRangeArray).Value = Application.Transpose(MyArray)
As I mentioned in comments, just use:
tRangeArray.Value = Application.Transpose(MyArray)
Sheets("sheet1").Range(tRangeArray).Value
not working, because Range
accepts either single parameter - string with range address (not range itself): Range(addr)
, either two parameters - top left and bottom right cells: Range(cell_1,cell_2)
这篇关于创建和VBA移调阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!