3

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:

http://www.mrexcel.com/forum/excel-questions/629320-application-transpose-visual-basic-applications-array.html

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)
1
  • 5
    tRangeArray.Value = Application.Transpose(MyArray) Commented Jun 27, 2014 at 16:13

2 Answers 2

8

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)

Sign up to request clarification or add additional context in comments.

Comments

2

Similar, but using Resize and Ubound:

Dim myarray As Variant
myarray = Array(1, 2, 3, 4, 5)
Sheets("sheet1").Range("A1").Resize(UBound(myarray), 1).Value = Application.Transpose(myarray)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.