How to get a sum of columns if criteria is met?

mtbthepro

Board Regular
Joined
Feb 22, 2017
Messages
91
Hello, how would I go about to modifying this code so that it will calculate the total of all the account totals? The code below is below is supposed to look for account totals in each department in each sheet and if that department has more than 1 account total the macro will give it a "grand total" at the end of that department but the grand total doesn't have numbers in it. So how can I gather the number from the account total and sum it into grand total.

Code:
Sub AddGT()  
    Dim ab As Range
    Dim i As Long, lRow As Long, j As Long
    Dim Streak As Integer
    Dim sht As Worksheet
    Dim wsn
    Dim nam As String
       
    Application.ScreenUpdating = False
    wsn = Array("Francisca", "Lucria", "Alberto", "Amanda", "Early Child", "Melanie", _
            "Natasha&Tom", "Maria", "Jess", "Grosv KDGN", "Tashana", "Space Rental")
      
   
       
    For j = LBound(wsn) To UBound(wsn)
        nam = wsn(j)
        Worksheets(nam).Activate
        MsgBox ActiveSheet.Name


        lRow = Cells(Rows.Count, 2).End(xlUp).Row
        Set ab = Range("B1:B" & lRow)
           


        For i = 1 To ab.Rows.Count
            If ab.Rows.Count = 1 Then Streak = 0
            If ab(i).Offset(0, -1) Like "Department*" Then
                If Streak >= 2 Then Cells(ab(i).Row - 1, 3).Value = "GRAND TOTAL"
                Streak = 0
            End If
            If ab(i) = "ACCOUNT TOTAL" Then Streak = Streak + 1
        Next
        If Streak >= 2 Then
            Streak = 0
            Cells(ab(i).Row + 1, 3).Value = "GRAND TOTAL"
        End If
    Next j
   Application.ScreenUpdating = True
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top