Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default HOW TO ASSIGN 2 DIMENSION ARRAY VALUES FROM 2 COLUMNS?

I need to assign dimension 1 with col A data and dimension 2 with col B data.
IOW, element 1 would consist of A1, B1, element 2 A2, B2... The number of
rows is not always the same. Can somebody provide an example of code to
accomplish this? Thanks! -JEFF-
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default HOW TO ASSIGN 2 DIMENSION ARRAY VALUES FROM 2 COLUMNS?

You can assign it to a variant variable
Dim v as Variant
in xl2000 and later you can also assign it to a dynamic variant array
Dim v() as Variant
However, assigning it to a variant works as well and is compatible back to
excel 5 where vba was introduced.

Dim v as Variant
v = Range("A1").currentRegion.Resize(,2).Value

for i = 1 to ubound(v,1)
for j = 1 to ubound(v,2)
debug.print i, j, v(i,j)
Next
Next


--
Regards,
Tom Ogilvy

"-JEFF-" wrote in message
...
I need to assign dimension 1 with col A data and dimension 2 with col B

data.
IOW, element 1 would consist of A1, B1, element 2 A2, B2... The number of
rows is not always the same. Can somebody provide an example of code to
accomplish this? Thanks! -JEFF-



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default HOW TO ASSIGN 2 DIMENSION ARRAY VALUES FROM 2 COLUMNS?

Jeff,

I believe this does it:

Sub test()
Dim test_array()
Dim first_dimension_count As Long
Dim i As Long

first_dimension_count = Range("A" & Rows.Count).End(xlUp).Row
ReDim test_array(1 To first_dimension_count, 1 To 2)
test_array = Range("A1:B" & first_dimension_count)
End Sub

hth,

Doug

"-JEFF-" wrote in message
...
I need to assign dimension 1 with col A data and dimension 2 with col B
data.
IOW, element 1 would consist of A1, B1, element 2 A2, B2... The number of
rows is not always the same. Can somebody provide an example of code to
accomplish this? Thanks! -JEFF-



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default HOW TO ASSIGN 2 DIMENSION ARRAY VALUES FROM 2 COLUMNS?

Thank You, Doug, works great!
-JEFF-

"Doug Glancy" wrote:

Jeff,

I believe this does it:

Sub test()
Dim test_array()
Dim first_dimension_count As Long
Dim i As Long

first_dimension_count = Range("A" & Rows.Count).End(xlUp).Row
ReDim test_array(1 To first_dimension_count, 1 To 2)
test_array = Range("A1:B" & first_dimension_count)
End Sub

hth,

Doug

"-JEFF-" wrote in message
...
I need to assign dimension 1 with col A data and dimension 2 with col B
data.
IOW, element 1 would consist of A1, B1, element 2 A2, B2... The number of
rows is not always the same. Can somebody provide an example of code to
accomplish this? Thanks! -JEFF-




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
Assign Values to array Jeff Excel Discussion (Misc queries) 14 July 15th 08 06:06 PM
Array transfer - 1 dimension v. 2 dimension JWolf[_2_] Excel Programming 2 June 29th 04 01:02 AM
Getting excel array dimension banavas[_3_] Excel Programming 3 June 8th 04 12:11 PM
How do I assign values to an array? Skyway[_2_] Excel Programming 14 February 29th 04 01:22 AM
single dimension array RobcPettit Excel Programming 3 January 20th 04 08:33 AM


All times are GMT +1. The time now is 09:41 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"