Variant Array

talonboi02

New Member
Joined
Apr 12, 2012
Messages
3
Hello! I’m a rookie VBA user and am having difficulties with a project.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
I have 3 worksheets in the same workbook entitled:<o:p></o:p>
data <o:p></o:p>
equipment<o:p></o:p>
station<o:p></o:p>

In the equipment worksheet, I have the following in columns 1, 2, 3<o:p></o:p>
<o:p></o:p>
EQUIP FC BC
(strings) (int) (int)<o:p></o:p>

I want to define an array for the equipment worksheet - a Variant array (with both Integer and String values) holding 185 rows and 3 columns and populate it with the data from the equipment worksheet.
<o:p></o:p>

<o:p></o:p>
Can someone direct me on how to create it? This is how bad I am at VBA – my attempt below:
<o:p></o:p>

<o:p></o:p>
Dim equipmentArray(0 to 184, 0 to 2) As Variant
Dim i = integer
<o:p>i = 0</o:p>
Sheets("equipment").Select<o:p></o:p>
Range("A3:C185").Select<o:p></o:p>
While (ActiveCell.Value <> "")<o:p></o:p>
equipmentArray (i, 0) = ActiveCell.Value<o:p></o:p>
equipmentArray (i, 1) = ActiveCell.Value<o:p></o:p>
equipmentArray (i, 2) = ActiveCell.Value<o:p></o:p>
ActiveCell.Offset(i + 1, 0).Select<o:p></o:p>
Wend<o:p></o:p>
<o:p>
</o:p>Doesn’t seem to work – I only get 1 column. Any help is appreciated!<o:p></o:p>

I'm guessing I'm missing a loop somewhere? Thanks.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
You could use this.
Code:
Dim varEquip As Variant
varEquip = Worksheets("Equipment").Range("A1:C185").Value

If you want to use an array that's already dimensioned you coudl use this.
Code:
Dim rng As Range
Dim cl As Range
Dim varEquip1(0 To 184, 0 To 2)
Dim I As Long
Set rng = Worksheets("Equipment").Range("A3:C185")
For Each cl In rng.Columns(1)

    varEquip1(I, 0) = cl.Value
    varEquip1(I, 1) = cl.Offset(, 1).Value
    varEquip1(I, 2) = cl.Offset(, 1).Value
    
    I = I + 1
Next cl
 
Upvote 0

Forum statistics

Threads
1,215,366
Messages
6,124,516
Members
449,168
Latest member
CheerfulWalker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top