Macro to Select

T

tc

hi. i have a worksheet which contains two columns, one with names and
the other with amounts, there is an empty cell between unique names
but thre is no empty cell in between amounts because of subtotals. i
need to create a macro that will select each of the unique names(may
occupy one or more rows) and the coresponding amounts and paste them
to a seperate worksheet. please help!
 
G

Guest

Sub test()

Sh2RowCount = 1
With Sheets("Sheet1")
Lastrow = .Cells(Rows.Count, "B").End(xlUp).Row
For RowCount = 1 To Lastrow
If .Cells(RowCount, "A").Value <> "" Then
MyName = .Cells(RowCount, "A").Value
Else
Subtotal = .Cells(RowCount, "B").Value

With Sheets("Sheet2")
.Cells(Sh2RowCount, "A").Value = MyName
.Cells(Sh2RowCount, "B").Value = Subtotal
End With
Sh2RowCount = Sh2RowCount + 1
End If
Next RowCount
End With
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