help with arrays

M

mike

I'm just getting started with arrays and could use some
help.

I want to go thru data and if col A = "X", then I want to
select Customer Name as Field 1 in the array, address as
Field 2 and telephone number as Field 3.

Then move to the next line with an "X" in col A.

then populate the second item in the array with the same 3
fields.

Move to the next field and populate the third item in the
array.

Once the array is populated, I will move to another sheet
and write out all of the data in the array.

One thing is that the data population will change in size
each time the macro is run.

I'm having trouble once I get to an "X" in col A, how do I
code that in the array, this is item 1 field 1, item 1
field 2 and item 1 field 3. AND when I find the next x
that it is item 2 field 1, item 2 field 2, item 2 field 3.

any help in getting started would be greatly appreciated.
Thanks for your help.
 
T

Tom Ogilvy

You could do this with one command using the Advance filter; a couple of
additional commands using the Autofilter.

But to use an array. Assume field1 is column B, field2 is column C and
field3 is column D

Sub CopyWithArray()
Dim myarray()
Dim ub As Long
Dim i As Long, rng As Range
Dim cell As Range
ub = Application.CountIf(Columns(1), "x")
ReDim myarray(1 To ub, 1 To 3)
Set rng = Range(Cells(1, 1), _
Cells(Rows.Count, 1).End(xlUp))
i = 0
For Each cell In rng
If LCase(cell.Value) = "x" Then
i = i + 1
myarray(i, 1) = cell.Offset(0, 1).Value
myarray(i, 2) = cell.Offset(0, 2).Value
myarray(i, 3) = cell.Offset(0, 3).Value
End If
Next
ActiveSheet.Next.Range("A1") _
.Resize(ub, 3).Value = myarray
End Sub
 

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

Top