#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"