Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default 2 dimensional array

This is what i do for a 1 dimensional array but i wondering how
to do a 2 dimensional. Then have Range("M" & x) = the first dimension
and have Range("M" & x).offset(0,1) = the second dimension. Just starting to
understand arrays.

Dim arrEmployee() As Variant
Dim strEmployee As Variant
Dim rng As Range
Dim x As Long
Set rng = Range(Cells(2, 3), Cells(Rows.Count, 3).End(xlUp))
x = 0
ReDim arrEmployee(1 To rng.Rows.Count)
For Each cell In rng
x = x + 1
arrEmployee(x) = cell.Value
Next cell

x = 2
For Each strEmployee In arrEmployee
Range("M" & x) = strEmployee
x = x + 1
Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 2 dimensional array

You can actually pickup the value from a range and end up with a 2 dimensional
array.

This would create a 2 dimensional array (5 rows by 1 column)
dim myArr as variant
myArr = activesheet.range("a1:A5").value

This would create a 2 dimensional array (5 rows by 2 columns)
dim myArr as variant
myArr = activesheet.range("a1:b5").value

So maybe you could use something like:

dim myArr as variant
with activesheet
myArr = activesheet.range("C2:D" & .cells(.rows.count,"C").end(xlup).row).value
end with







Mike wrote:

This is what i do for a 1 dimensional array but i wondering how
to do a 2 dimensional. Then have Range("M" & x) = the first dimension
and have Range("M" & x).offset(0,1) = the second dimension. Just starting to
understand arrays.

Dim arrEmployee() As Variant
Dim strEmployee As Variant
Dim rng As Range
Dim x As Long
Set rng = Range(Cells(2, 3), Cells(Rows.Count, 3).End(xlUp))
x = 0
ReDim arrEmployee(1 To rng.Rows.Count)
For Each cell In rng
x = x + 1
arrEmployee(x) = cell.Value
Next cell

x = 2
For Each strEmployee In arrEmployee
Range("M" & x) = strEmployee
x = x + 1
Next


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 2 dimensional array

Dim arrEmployee() As Variant
Dim strEmployee As Variant
Dim rng As Range
Dim x As Long
Set rng = Range(Cells(2, 3), Cells(Rows.Count, 3).End(xlUp))
x = 0
ReDim arrEmployee(1 To rng.Rows.Count,2)
For Each cell In rng
x = x + 1
arrEmployee(x,1) = cell.Value
arrEmployee(x,2) = cell.offset(0,1).Value
Next cell

x = 2
For EmployeeCount = 1 to Ubound(arrEmployee)
Range("M" & x) = arrEmployee(EmployeeCount,1)
Range("M" & x).offset(0,1) = arrEmployee(EmployeeCount,2)
x = x + 1
Next

"Mike" wrote:

This is what i do for a 1 dimensional array but i wondering how
to do a 2 dimensional. Then have Range("M" & x) = the first dimension
and have Range("M" & x).offset(0,1) = the second dimension. Just starting to
understand arrays.

Dim arrEmployee() As Variant
Dim strEmployee As Variant
Dim rng As Range
Dim x As Long
Set rng = Range(Cells(2, 3), Cells(Rows.Count, 3).End(xlUp))
x = 0
ReDim arrEmployee(1 To rng.Rows.Count)
For Each cell In rng
x = x + 1
arrEmployee(x) = cell.Value
Next cell

x = 2
For Each strEmployee In arrEmployee
Range("M" & x) = strEmployee
x = x + 1
Next

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default 2 dimensional array

Thanks Joel

"Joel" wrote:

Dim arrEmployee() As Variant
Dim strEmployee As Variant
Dim rng As Range
Dim x As Long
Set rng = Range(Cells(2, 3), Cells(Rows.Count, 3).End(xlUp))
x = 0
ReDim arrEmployee(1 To rng.Rows.Count,2)
For Each cell In rng
x = x + 1
arrEmployee(x,1) = cell.Value
arrEmployee(x,2) = cell.offset(0,1).Value
Next cell

x = 2
For EmployeeCount = 1 to Ubound(arrEmployee)
Range("M" & x) = arrEmployee(EmployeeCount,1)
Range("M" & x).offset(0,1) = arrEmployee(EmployeeCount,2)
x = x + 1
Next

"Mike" wrote:

This is what i do for a 1 dimensional array but i wondering how
to do a 2 dimensional. Then have Range("M" & x) = the first dimension
and have Range("M" & x).offset(0,1) = the second dimension. Just starting to
understand arrays.

Dim arrEmployee() As Variant
Dim strEmployee As Variant
Dim rng As Range
Dim x As Long
Set rng = Range(Cells(2, 3), Cells(Rows.Count, 3).End(xlUp))
x = 0
ReDim arrEmployee(1 To rng.Rows.Count)
For Each cell In rng
x = x + 1
arrEmployee(x) = cell.Value
Next cell

x = 2
For Each strEmployee In arrEmployee
Range("M" & x) = strEmployee
x = x + 1
Next

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
Export 1-dimensional array values to a two-dimensional table? Laurie Excel Programming 2 November 8th 07 03:51 PM
Changing a two-dimensional, one row array to one-dimensional Alan Beban[_2_] Excel Programming 1 September 16th 07 08:56 PM
Returning an array from a multi-dimensional array Chris Excel Programming 2 January 3rd 07 06:01 AM
Mutli-dimensional Array to Single-Dimension Array Blue Aardvark Excel Programming 3 October 15th 05 09:22 AM
Create One-Dimensional Array from Two-Dimensional Array Stratuser Excel Programming 1 February 23rd 05 08:46 PM


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