Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Array

Read the help file on Redim ' ng an array. It says you can only redim
preserve the last dimension. But you don't need to do it anyway, so use
this:


Sub TransposeThat()
Dim TArray() As Variant
Dim DB as Range, i as Long, j as Long
Dim nRows as Long, nCols as Long
Set DB = Selection
nrows = DB.Rows.Count
ncols = DB.Columns.Count
redim TArray(1 to ncols, 1 to nrows)
For i = 1 To nrows
For j = 1 To ncols
TArray(j, i) = DB(i, j)
Next j
Next i
End Sub


--
Regards,
Tom Ogilvy


"Bill" wrote in message
nk.net...
Hello,
I want to transpose a range in an excel data and store the values in an
array. The code I have is:

Sub TransposeThat()
Set DB = Selection
nrows = DB.Rows.Count
ncols = DB.Columns.Count
For i = 1 To nrows
For j = 1 To ncols
ReDim Preserve TArray(1 To j, 1 To i)
TArray(j, i) = DB(i, j)
Next j
Next i
End Sub

DB is the range on the worksheet. I get the message: subscript out of

range
applying to the redim preserve statement.

Why am I getting that error?

Thanks,

bill




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prevent cell/array references from changing when altering/moving thecell/array nme Excel Discussion (Misc queries) 1 September 19th 08 01:53 PM
meaning of : IF(Switch; Average(array A, array B); array A) DXAT Excel Worksheet Functions 1 October 24th 06 06:11 PM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 6 November 9th 05 05:54 AM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 1 November 8th 05 04:21 AM
variant array containing cel adresses convert to actual ranges-array Peter[_21_] Excel Programming 5 December 10th 03 09:50 PM


All times are GMT +1. The time now is 06:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"