Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to Sum
Sub ABC()
Dim rng as Range, cell as Range Dim sum as Long set rng = Range(cells(2,"A"),Cells(2,"A").End(xldown)) for each cell in rng sum = val(cell.offset(0,1)) + sum if cell.value < cell.Offset(1,0).Value then cell.offset(0,2).Value = sum & " pc" sum = 0 end if Next Cells(1,3).Value = "Subtotal" End Sub right now it looks in A2 to see the first A001. Adjust the code to look at the correct location. -- Regards, Tom Ogilvy "hon123456" wrote in message ups.com... Dear all, I have excel data as follows: NO Pieces --------- ---------- A001 10 pc A001 20 pc A001 30 pc A002 15 pc A002 15 pc NowI want to write a VBA to sum a subtotal for the column of A001 and A002, the outcomes should as follows: NO Pieces Subtotal --------- ---------- ------------ A001 10 pc A001 20 pc A001 30 pc 60pc A002 15 pc A002 15 pc 30pc How can I do that in Excel with VBA or other method ? Thanks. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|