Sub Totals()
Dim lngLastRow As Long
Dim lngRow As Long
Dim curRevenue As Currency
Dim curBackLog As Currency
lngLastRow = Range("A1048576").End(xlUp).Row
For lngRow = 2 To lngLastRow
If Cells(lngRow, 1) = "Total" Then
Cells(lngRow, 3) = curRevenue
lngRow = lngRow + 1
Cells(lngRow, 3) = curBackLog
curRevenue = 0
curBackLog = 0
Else
If Cells(lngRow, 2) = "Revenue" Then
curRevenue = curRevenue + Cells(lngRow, 3)
Else
curBackLog = curBackLog + Cells(lngRow, 3)
End If
End If
Next
End Sub
so this macro doesn't care how many columns or rows I have? it will always update the revenue rows no matter?That's correct.
how would I set up the macro to run anytime a revenue dollar amount is changed?
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range(UsedRange.Address)) Is Nothing Then
If Cells(Target.Row, 2) = "Revenue" Then
Application.EnableEvents = False
RevenueTotals
Application.EnableEvents = True
End If
End If
End Sub
If Cells(lngRow, REVENUE_COL) = "Revenue" Then
' Sum the revenue values. Val() returns zero when the value is a space.
If Cells(lngRow, REVENUE_COL) = "Revenue" And Cells(lngRow, MATERIAL_COL) = "Total" Then
' Sum the revenue values. Val() returns zero when the value is a space.