Okay, I've generalized my code to make it easier for you to change in the
future if necessary. The controlling parameters (product name and output
column) are now specified in two Const (the VB keyword for "constant")
statements... the names should tell you what to assign to each. I also
change the data type for the Total (and, now, GrandTotal also) to Double
from the Long I had originally declared them as. This will not affect the
output for the example data you posted, but will allow these two totals to
track pennies as well as dollars if necessary. I also corrected a minor flaw
in how I checked the product names so that now the product names do not have
to all be listed in the same letter casing. The grand totals for the product
being added up in each section is shown 2 rows below the last total in the
specified column (I thought the blank row made the display less confusing).
Sub SumProductbySectionsWithGrandTotal()
Dim Total As Double, GrandTotal As Double
Dim X As Long, FirstRow As Long, LastRow As Long
'
Const OutputColumn As String = "A"
Const ProductName As String = "PRODUCT A"
'
With Worksheets("Sheet1")
FirstRow = .Columns(OutputColumn).Find("*", After:=Cells( _
.Rows.Count, OutputColumn)).Row
LastRow = .Cells(.Rows.Count, OutputColumn).End(xlUp).Row + 1
For X = FirstRow To LastRow
If Len(.Cells(X, "B").Value) = 0 Then
.Cells(X, OutputColumn).Value = Total
GrandTotal = GrandTotal + Total
Total = 0
ElseIf UCase(.Cells(X, "A")) = UCase(ProductName) Then
Total = Total + .Cells(X, "B").Value
End If
Next
.Cells(LastRow + 2, OutputColumn).Value = GrandTotal
End With
End Sub