PC Review


Reply
Thread Tools Rate Thread

2 dimensional array

 
 
Mike
Guest
Posts: n/a
 
      20th Nov 2008
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 With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      20th Nov 2008
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" & .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
 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      20th Nov 2008
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 With Quote
 
Mike
Guest
Posts: n/a
 
      20th Nov 2008
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Export 1-dimensional array values to a two-dimensional table? =?Utf-8?B?TGF1cmll?= Microsoft Excel Programming 2 8th Nov 2007 03:51 PM
Extracting single dimensional array out of two dimensional array Mukesh Microsoft C# .NET 5 24th Oct 2007 11:22 PM
flatten multi-dimensional array to on-dimensional array per9000 Microsoft C# .NET 8 4th Dec 2006 09:46 AM
copy 1 dimensional to 2 dimensional array with actual int values j-in-uk Microsoft C# .NET 3 12th May 2006 09:23 AM
RE: array copy from single-dimensional to multi-dimensional =?Utf-8?B?bWFyaw==?= Microsoft VB .NET 0 30th Jul 2004 11:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:32 PM.