Thread: VBA Loop Code
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default VBA Loop Code

Hi,

Try this. Change SrcSheet & DestSheet to the correct sheets

Sub sonic()
Dim x As Long
Dim SrcSheet As String
Dim DestSheet As String
SrcSheet = "Sheet1"
DestSheet = "Sheet2"
x = 2
LastRow = Sheets(SrcSheet).Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Sheets(SrcSheet).Range("A2:A" & LastRow)
For Each c In MyRange
Sheets(DestSheet).Cells(x, 1) = c.Value
Sheets(DestSheet).Cells(x, 2) = c.Offset(, 2).Value
x = x + 1
Next
End Sub

Mike

"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!