How To Insert 3 Rows and Total

E

ed.cabrera

I've been knocking myself out since yesterday trying to figure
something out. I have some self-taught experience with VBA macros in
Excel, but just can't get this. And I bet it's simple. Here's the
deal:

I have a monthly spreadsheet that lists users and their cell phone
expenses. There is typically 4 - 6 rows for each user. I want to
write a macro that will look at the cell that contains the name,
compare it to the cell below it. Then if they match, move down one
cell and compare again. Then when it fines a difference, add 3 rows,
put a subtotal under the expense cells; and then go back to analyzing
the name cells looking for the next break and resume.

Is that confusing? Would anybody be able to help me out with
this ...I'd be very greatful!

Thanks
 
J

Joel

You didn't specify which columns you used so yo need to change the references
to Column A & b


Sub GetTotal()

RowCount = 1
StartRow = RowCount
Do While Range("A" & RowCount) <> ""
If Range("A" & RowCount) <> Range("A" & (RowCount + 1)) Then
'add 3 rows
Rows(RowCount + 1).Insert
Rows(RowCount + 1).Insert
Rows(RowCount + 1).Insert
'put formula for total
Range("B" & (RowCount + 2)).Formula = _
"=Sum(B" & StartRow & ":B" & RowCount & ")"
Range("A" & (RowCount + 2)) = "TOTAL"
RowCount = RowCount + 4
StartRow = RowCount
Else
RowCount = RowCount + 1
End If
Loop

End Sub
 
H

Hennie Neuhoff

Joel tks very much, I needed exactly the same macro, however for som or other
reason my macro doesn't work ?? I think it's got something to do with the ref
to the columns. In my spreadsheet the names appear in C and the amounts in D.
Any help would be appreciated
 

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