View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Custom Calculations in Subtotal

After you do the Subtotals, you can run this macro:

Sub AddFormulas()
Dim rng As Range
Dim cell As Range
With ActiveSheet
Set rng = Intersect(.Columns(1), _
.UsedRange).Cells
rng(1).Offset(0, 3).Value = " Sale +/- Hist"
Set rng = rng.Offset(1, 0).Resize(rng.Rows.Count - 1)
For Each cell In rng
cell.Offset(0, 3).Formula = "=(" & cell.Offset(0, 1).Address _
& " - " & cell.Offset(0, 2).Address & ")/" & _
cell.Offset(0, 1).Address & "*100"
cell.Offset(0, 3).NumberFormat = "#0.00"

Next
End With
End Sub

Regards,
Tom Ogilvy

"Con Tang" wrote in message
...
Hi,

I know/understand that I will need to do this in a macro, however, I
don't know how to do this. I can record a macro and it shows me the
code, but I don't know how to modify it to allow for custom
calculations. Sorry for being such a noob, but any help would be much
appreciated.



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!