VBA Loop Code
What happens when you get to 9000. Is this also printed, and do you keep going past 9000, 9001, 9002, etc? Where do you stop?
This code assumes 9000 is not printed:
Sub test()
Const cFirstRow = 2
Const cValueCol = 1, cColourCol = 3
Dim i As Long, lng As Long, lngLimit As Long, strColour As String
Dim rngDest As Range
Set rngDest = Sheet2.Cells(1, 1)
With Sheet1
i = cFirstRow
lng = .Cells(i, cValueCol)
Do
strColour = .Cells(i, cColourCol)
i = i + 1
lngLimit = .Cells(i, cValueCol)
If lngLimit = 0 Then Exit Do
Do
rngDest = lng
rngDest.Offset(0, 1) = strColour
Set rngDest = rngDest.Offset(1)
lng = lng + 1
Loop While lng < lngLimit
Loop
End With
End Sub
Cheers,
Rob
On 12-Dec-2009 10:56, D. Stacy wrote:
I have three column of data and I would like to use VBA code to go loop thru
the rows of data and then write output to another worksheet.
Value Range Label
1400 175 Red
2400 112 Blue
9000 710 Green
The output table (range) would look something like
1400 Red
1401 Red
1402 Red
1403 Red
...
...
...
..
2400 Blue
2401 Blue
etc. etc.
Thanks in advance!
|