Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Dimention & manipulation of Variant array

I use variant array (ie. dim array as variant) to read a range from a
sheet into to an array to avoid loops.

I found the array is always 2D, even when I read a single row or
column. Is there a way (or another way if I did wrong) to make it 1D
array?

Further more, is it possible to get single row or column from this kind
of 2D array quickly, like array(1) or array(1, *)?

Hopefull I made it clear, thank you.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Dimention & manipulation of Variant array



"muster" wrote in message
oups.com...
I use variant array (ie. dim array as variant) to read a range from a
sheet into to an array to avoid loops.

I found the array is always 2D, even when I read a single row or
column. Is there a way (or another way if I did wrong) to make it 1D
array?


That is right, because a range has rows and columns, so it always allows for
multiples


Further more, is it possible to get single row or column from this kind
of 2D array quickly, like array(1) or array(1, *)?


Don't think so, you need to loop through if you want it single dimension.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Dimention & manipulation of Variant array

For a single row, you use application.Transpose twice. For a single column,
you use it once:

Sub efg()
Dim vr As Variant, vc As Variant
Dim vRow As Variant, vCol As Variant
Dim rngRow As Range, rngColumn As Range
Set rngRow = Range("A1:Z1")
Set rngCol = Range("A1:A20")
vRow = rngRow.Value
vr = Application.Transpose(Application.Transpose(vRow))
Debug.Print UBound(vr, 1)
vCol = rngCol.Value
vc = Application.Transpose(vCol)
Debug.Print UBound(vc, 1)
End Sub

--
Regards,
Tom Ogilvy


"muster" wrote:

I use variant array (ie. dim array as variant) to read a range from a
sheet into to an array to avoid loops.

I found the array is always 2D, even when I read a single row or
column. Is there a way (or another way if I did wrong) to make it 1D
array?

Further more, is it possible to get single row or column from this kind
of 2D array quickly, like array(1) or array(1, *)?

Hopefull I made it clear, thank you.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 200
Default Dimention & manipulation of Variant array

Bob Phillips wrote:
"muster" wrote in message
oups.com...
I use variant array (ie. dim array as variant) to read a range from a
sheet into to an array to avoid loops.

I found the array is always 2D, even when I read a single row or
column. Is there a way (or another way if I did wrong) to make it 1D
array?


That is right, because a range has rows and columns, so it always allows for
multiples


Further more, is it possible to get single row or column from this kind
of 2D array quickly, like array(1) or array(1, *)?


Don't think so, you need to loop through if you want it single dimension.


If you want MyArray2 to be the nth column of MyArray1

MyArray2 = Application.Index(MyArray1, 0, n)

For the nth row

MyArray2 = Application.Index(MyArray1, n, 0)

In the second case MyArray2 will be one-dimensional

Alan Beban
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 200
Default Dimention & manipulation of Variant array

Another method of getting a one-dimensional array from a two-dimensional
single row array is

vRow = Application.Index(vRow, 1, 0)

Alan Beban

Tom Ogilvy wrote:
For a single row, you use application.Transpose twice. For a single column,
you use it once:

Sub efg()
Dim vr As Variant, vc As Variant
Dim vRow As Variant, vCol As Variant
Dim rngRow As Range, rngColumn As Range
Set rngRow = Range("A1:Z1")
Set rngCol = Range("A1:A20")
vRow = rngRow.Value
vr = Application.Transpose(Application.Transpose(vRow))
Debug.Print UBound(vr, 1)
vCol = rngCol.Value
vc = Application.Transpose(vCol)
Debug.Print UBound(vc, 1)
End Sub

Reply
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
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
ReDim Object array as parameter of Variant array Peter T Excel Programming 4 May 10th 05 02:11 PM
Variant Array Steph[_3_] Excel Programming 1 June 2nd 04 01:29 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 03:17 AM.

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

About Us

"It's about Microsoft Excel"