I need a macro that will total numbers from duplicate entries and move the totals to new cells. As you can see on the attached sample the name "Albright" has two lines of amounts. I would need the total of F2 and F3 placed in I2, it would also have to total and move G2 and G3, H2 and H3 to J2 and K2 respectively. I would have to run the macro manually as I have 3500 lines with these double entries stuck in at different places. My active cell in this instance would be A2 I would run the macro it would do the calculations, move the totals then delete the duplicate row. I have made other macros to move and delete rows but never had one with a formula in it. Thanks for all the help.
Try this on a copy of your data...
Sub Total_then_Delete() Dim vD As Variant Dim x As Long Dim y As Integer With Worksheets("Sheet1") vD = .Cells(1).CurrentRegion.Resize(, 11) For x = UBound(vD) - 1 To 1 Step -1 If vD(x, 1) = vD(x + 1, 1) Then vD(x, 9) = vD(x, 6) + vD(x + 1, 6) vD(x, 10) = vD(x, 7) + vD(x + 1, 7) vD(x, 11) = vD(x, 8) + vD(x + 1, 8) For y = 1 To 8 vD(x + 1, y) = "" Next y End If Next x .Cells(1).Resize(UBound(vD), 11) = vD .Columns(1).SpecialCells(xlCellTypeBlanks).EntireRow.Delete End With End Sub
Hi cmefix and welcome to the forum,
This problem looks like a Pivot Table Answer to me. See the attached to see if it does what you need without code or formulas.
One test is worth a thousand opinions.
Click the * below to say thanks.
MarvinP the pivot table would work on a smaller scale unfortunately I am working with some very large work sheets with too many odd variables but thank you.
Dangelor at first your macro would not work, I tried it again on the sample and it worked fine. I then debugged it and not really knowing how to write a macro such at this I was stumped. But the longer I looked at it the more I picked up what the numbers meant! The debugger stopped at vD(x, 10) = vD(x, 7) + vD(x + 1, 7) and finally understanding what the numbers meant I looked down column 7 and found improperly formatted numbers. I just knew it was going to run after I cleaned them up and wow did it, 3500 lines processed with the click of a button. I have 4 more spread sheets to get to, this time I will clean them up ahead of time. I can see I have a lot to learn going from my simple cut and move macros to this.
Thank you both for replying to this I really appreciate it. Dangelor you saved me big time thank you.
Glad I could help!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks