devakotia
devakotia

Reputation: 101

copying array onto range of cells

I want to copy the values of the array mastersheet() onto a range of cells of equal size.

mastersheet() is initially declared as a variant Dim mastersheet() As Variant

Eventually in the code it has 4 "columns" or dimensions. ReDim mastersheet(1, 1, 1, 1)

Eventually strings are added to it in column 2, or the second dimension. Not all column have the same data type.

wbmastersheet.Worksheets(1).range("A1:D" & UBound(mastersheet, 4)) = mastersheet()

I am getting the below error

Error 13: type mismatch

Can anyone please resolve this ?

Upvotes: 1

Views: 39

Answers (1)

user4039065
user4039065

Reputation:

You seem to be confusing the rank with the actual dimension.

Rewrite your code so that mastersheet is 1 to x, 1 to 4. Put the values into the array as,

redim mastersheet(1 to 2, 1 to 4)
mastersheet(1, 1) = "A1"
mastersheet(1, 2) = "B1"
mastersheet(1, 3) = "C1"
mastersheet(1, 4) = "D1"
mastersheet(2, 1) = "A2"
mastersheet(2, 2) = "B2"
mastersheet(2, 3) = "C2"
mastersheet(2, 4) = "D2"

Write the values back to the worksheet like this,

wbmastersheet.Worksheets(1).range("A1").Resize(UBound(mastersheet, 1), UBound(mastersheet, 2)) = mastersheet

Upvotes: 1

Related Questions