Populating Two Dimensional Array

  • Thread starter Thread starter willz99ta via OfficeKB.com
  • Start date Start date
W

willz99ta via OfficeKB.com

Howdy,

I'm trying to find the right syntax to fill a two dimensional with the first
two columns in my excel spreadsheet. The two columns could have as few as 1
or as many as 60,000 records in them.

Thanks,
Will
 
You could loop but the quickest method is to use a variant variable:

Dim myArray As Variant
Set myArray = Selection

Then, for example (if you've used columns A and B), myArray(1,1) will be
A1's value, myArray(1,2) B1's, myArray(2,1) A2's, etc.
 
I can't use the selection function since this is part of a larger program.
What is the easiest way to loop it?

Thanks again,
Will

You could loop but the quickest method is to use a variant variable:

Dim myArray As Variant
Set myArray = Selection

Then, for example (if you've used columns A and B), myArray(1,1) will be
A1's value, myArray(1,2) B1's, myArray(2,1) A2's, etc.
[quoted text clipped - 4 lines]
Thanks,
Will
 
Dim v as Variant
lastrow = cells(rows.count,1).End(xlup).Row
v = Range("A1:B" & lastRow).Value

' look at the results:
msgbox lbound(v,1) & ", " & ubound(v,1) & _
vbNewLine & lbound(v,2) & ", " & ubound(v,2)
 
Try doing what was suggested, but first use VBA to do the selection
automagically:

dim LastRow as Long
LastRow = range("A1").end(xldown).row
range("A1:B" & LastRow).select

Bill
------------------------
willz99ta via OfficeKB.com said:
I can't use the selection function since this is part of a larger program.
What is the easiest way to loop it?

Thanks again,
Will

You could loop but the quickest method is to use a variant variable:

Dim myArray As Variant
Set myArray = Selection

Then, for example (if you've used columns A and B), myArray(1,1) will be
A1's value, myArray(1,2) B1's, myArray(2,1) A2's, etc.
[quoted text clipped - 4 lines]
Thanks,
Will
 
Selecting in rarely required and when not, not recommended. It isn't
required in this case.

dim v as Variant
dim LastRow as Long
LastRow = range("A1").end(xldown).row
v = range("A1:B" & LastRow).Value


--
Regards,
Tom Ogilvy


Bill Martin said:
Try doing what was suggested, but first use VBA to do the selection
automagically:

dim LastRow as Long
LastRow = range("A1").end(xldown).row
range("A1:B" & LastRow).select

Bill
------------------------
willz99ta via OfficeKB.com said:
I can't use the selection function since this is part of a larger program.
What is the easiest way to loop it?

Thanks again,
Will

You could loop but the quickest method is to use a variant variable:

Dim myArray As Variant
Set myArray = Selection

Then, for example (if you've used columns A and B), myArray(1,1) will be
A1's value, myArray(1,2) B1's, myArray(2,1) A2's, etc.

Howdy,

[quoted text clipped - 4 lines]
Thanks,
Will
 
Thanks Tom.

Bill
---------------
Tom Ogilvy said:
Selecting in rarely required and when not, not recommended. It isn't
required in this case.

dim v as Variant
dim LastRow as Long
LastRow = range("A1").end(xldown).row
v = range("A1:B" & LastRow).Value


--
Regards,
Tom Ogilvy


Bill Martin said:
Try doing what was suggested, but first use VBA to do the selection
automagically:

dim LastRow as Long
LastRow = range("A1").end(xldown).row
range("A1:B" & LastRow).select

Bill
------------------------
willz99ta via OfficeKB.com said:
I can't use the selection function since this is part of a larger
program.
What is the easiest way to loop it?

Thanks again,
Will


Martin wrote:
You could loop but the quickest method is to use a variant variable:

Dim myArray As Variant
Set myArray = Selection

Then, for example (if you've used columns A and B), myArray(1,1) will
be
A1's value, myArray(1,2) B1's, myArray(2,1) A2's, etc.

Howdy,

[quoted text clipped - 4 lines]
Thanks,
Will
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top