Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

run time error 1004 when transposing array to range

Status
Not open for further replies.

cg85cg

Technical User
Nov 4, 2006
18
US
Here is the trouble line

Workbooks("Most Up.xls").Worksheets(1).Range(Cells(1, 1), Cells(UBound(mostup, 1), UBound(mostup, 2))).Value = mostup

Similar lines have worked in other programs

When this line is executed:
mostup is a 2 dimensional array (1 to 64350, 1 to 31)
The array is being transposed over existing data on the worksheet

The range should be the same size as the array because of the Ubounds when defining the cells. I do not know where to go from here. I can provide more code if necessary.
 



Hi,

"mostup is a 2 dimensional array (1 to 64350, 1 to 31)
The array is being transposed over existing data on the worksheet"

It that's the case, then the transpose would be 31 rows by 64359 columns.

Do you see a problem in that? I do.

Skip,

[glasses] [red][/red]
[tongue]
 
i am confused. I thought that when declaring a 2D array the format is this:

DIM mostup(rows,columns)
 
huh...well that's interesting. how should i fix this problem? i could write a loop that would switch the rows and columns before I transpose, but i'm sure there is a more elegant solution.
 


"...could write a loop that would switch the rows and columns before I transpose...

Are we talking the same language?

TRANSPOSE means to SWITCH rows & columns.

By TRANSPOSE, do you mean getting the array into the worksheet?

Skip,

[glasses] [red][/red]
[tongue]
 
hmm...yes that is what i mean. I have never run into a problem where my rows and columns have been switched by the transpose funtion, there was nothing to suggest that transpose meant to switch them. i found the transpose function when searching online for how to put the contents of an arraty into a range. is there a better way to transfer the data?
 


"...there was nothing to suggest that transpose meant to switch them..."

HELP said:
TRANSPOSE

Returns a vertical range of cells as a horizontal range, or vice versa.

Skip,

[glasses] [red][/red]
[tongue]
 



"...I have never run into a problem where my rows and columns have been switched by the transpose funtion..."

There would not be a problem if you had less than 256 rows.

"is there a better way to transfer the data?"

EXACTLY what is your objective? Please use the term, TRANSPOSE, correctly. Please be painfully detailed, as I cannot see within your head. Please be CLEAR, CONCISE & COMPLETE.

Skip,

[glasses] [red][/red]
[tongue]
 
do you have your OPTION BASE set to 1 or 0 in your module?

I have had issues before when option base 0 (default) is used as ubound will return 1 less than you imagine as the array index starts from 0 rather than 1

try entering

Option Base 1

as the 1st line in your module and see if that does the trick

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
yes option base one is true.

i have an array that i am putting values into from other arrays. this array needs to be transfered to a worksheet. the range of cells to which the array is being transfered will be defined in size by the array itself by using UBound(array). the line that originally gave the error message is as follows:

Workbooks("Most Up.xls").Worksheets(1).Range(Cells(1, 1), Cells(UBound(mostup, 1), UBound(mostup, 2))).Value = mostup

where mostup is a 2D array (1 to 64350, 1 to 31)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top