VBA SUMIF Criteria/Ranges in different sheets

Werra2006

New Member
Joined
Jan 23, 2013
Messages
11
Hello


I need to modify my code to do a summary in the data capture worksheet of totals based on matching lookup ref for each business area.

Thank you in advance








Raw Data
[TABLE="width: 3280"]
<TBODY>[TR]
[TD]Lookup Ref</SPAN>
[/TD]
[TD]Report Date</SPAN>
[/TD]
[TD]Account</SPAN>
[/TD]
[TD]Name</SPAN>
[/TD]
[TD]Customer
Group
</SPAN>
[/TD]
[TD]Legal
Entity
</SPAN>
[/TD]
[TD]Business Unit</SPAN>
[/TD]
[TD]Roll Up</SPAN>
[/TD]
[TD]Business Area</SPAN>
[/TD]
[TD]Contract Region</SPAN>
[/TD]
[TD]Direct Responsible
Individual
</SPAN>
[/TD]
[TD]Cost Centre</SPAN>
[/TD]
[TD]Cost Centre Desc.</SPAN>
[/TD]
[TD]Activity</SPAN>
[/TD]
[TD]Tran
Type
</SPAN>
[/TD]
[TD]Tran
Ref
</SPAN>
[/TD]
[TD]Voucher
Number
</SPAN>
[/TD]
[TD]Credit Limit</SPAN>
[/TD]
[TD]Terms Of
Payment
</SPAN>
[/TD]
[TD]Date</SPAN>
[/TD]
[TD]Due
Date
</SPAN>
[/TD]
[TD]Ageing
Days
</SPAN>
[/TD]
[TD]Inv / CN
CC = LE
Indicator
</SPAN>
[/TD]
[TD]Net</SPAN>
[/TD]
[TD]VAT</SPAN>
[/TD]
[TD]Gross</SPAN>
[/TD]
[TD]Part
Settlements
</SPAN>
[/TD]
[TD]Unallocated
Cash
</SPAN>
[/TD]
[TD]Balance</SPAN>
[/TD]
[TD]0-30</SPAN>
[/TD]
[TD]31-60</SPAN>
[/TD]
[TD]61-90</SPAN>
[/TD]
[TD]91-120</SPAN>
[/TD]
[TD]121-150</SPAN>
[/TD]
[TD]151-180</SPAN>
[/TD]
[TD]181-210</SPAN>
[/TD]
[TD]211-240</SPAN>
[/TD]
[TD]241-270</SPAN>
[/TD]
[TD]271-300</SPAN>
[/TD]
[TD]301-330</SPAN>
[/TD]
[TD]331-360</SPAN>
[/TD]
[TD]360+</SPAN>
[/TD]
[TD]30+</SPAN>
[/TD]
[TD]60+</SPAN>
[/TD]
[TD]90+</SPAN>
[/TD]
[TD]120 +</SPAN>
[/TD]
[TD]150+</SPAN>
[/TD]
[TD]180+</SPAN>
[/TD]
[TD]28/02/13</SPAN>
[/TD]
[TD].Ageing</SPAN>
[/TD]
[TD]Ageing</SPAN>
[/TD]
[TD]Net
Provision</SPAN>

[/TD]
[/TR]
[TR]
[TD]3 - TFM/Security 41333</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]3 - TFM/Security</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]0</SPAN>
[/TD]
[TD][/TD]
[TD]17,038.84</SPAN>
[/TD]
[TD]3,407.77</SPAN>
[/TD]
[TD]20,446.61</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]20,446.61</SPAN>
[/TD]
[TD]20,446.61</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0</SPAN>
[/TD]
[TD]0-30</SPAN>
[/TD]
[TD]0-30</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[/TR]
[TR]
[TD]3 - TFM/Security 41333</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]3 - TFM/Security</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]28</SPAN>
[/TD]
[TD][/TD]
[TD]17,038.84</SPAN>
[/TD]
[TD]3,407.77</SPAN>
[/TD]
[TD]20,446.61</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]20,446.61</SPAN>
[/TD]
[TD]20,446.61</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]28</SPAN>
[/TD]
[TD]0-30</SPAN>
[/TD]
[TD]0-30</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[/TR]
[TR]
[TD]3 - TFM/Security 41333</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]3 - TFM/Security</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]59</SPAN>
[/TD]
[TD][/TD]
[TD]15,188.07</SPAN>
[/TD]
[TD]3,037.61</SPAN>
[/TD]
[TD]18,225.68</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]18,225.68</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]18,225.68</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]18,225.68</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[TD]59</SPAN>
[/TD]
[TD]31-60</SPAN>
[/TD]
[TD]31-60</SPAN>
[/TD]
[TD]0.00</SPAN>
[/TD]
[/TR]
</TBODY>[/TABLE]

Data Capture

[TABLE="width: 1673"]
<TBODY>[TR]
[TD]Lookup ref</SPAN>[/TD]
[TD="colspan: 4"]1 - National Accounts</SPAN>[/TD]
[TD] [/TD]
[TD="colspan: 4"]2 - Cleaning</SPAN>[/TD]
[TD]Lookup ref</SPAN>[/TD]
[TD="colspan: 4"]3 - TFM/SECURITY</SPAN>[/TD]
[TD]Lookup ref</SPAN>[/TD]
[TD="colspan: 4"]4 - Historic Contracts</SPAN>[/TD]
[TD]Lookup ref</SPAN>[/TD]
[TD="colspan: 4"]5 - BUOHEAD (Commercial)</SPAN>[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Total Debt</SPAN>[/TD]
[TD]DSO</SPAN>[/TD]
[TD][/TD]
[TD]90+</SPAN>[/TD]
[TD]60+</SPAN>[/TD]
[TD]Total Debt</SPAN>[/TD]
[TD]DSO</SPAN>[/TD]
[TD][/TD]
[TD]90+</SPAN>[/TD]
[TD]60+</SPAN>[/TD]
[TD]Total Debt</SPAN>[/TD]
[TD]DSO</SPAN>[/TD]
[TD][/TD]
[TD]90+</SPAN>[/TD]
[TD]60+</SPAN>[/TD]
[TD]Total Debt</SPAN>[/TD]
[TD]DSO</SPAN>[/TD]
[TD][/TD]
[TD]90+</SPAN>[/TD]
[TD]60+</SPAN>[/TD]
[TD]Total Debt</SPAN>[/TD]
[TD]DSO</SPAN>[/TD]
[/TR]
[TR]
[TD]1 - National Accounts 41305</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]2 - Cleaning 41305</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]3 - TFM/SECURITY 41305</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]4 - Historic Contracts 41305</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]5 - BUOHEAD (Commercial) 41305</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1 - National Accounts 41333</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD="align: right"]£8,780,750</SPAN>[/TD]
[TD] [/TD]
[TD]2 - Cleaning 41333</SPAN>[/TD]
[TD="align: right"]£129,263</SPAN>[/TD]
[TD="align: right"]£294,613</SPAN>[/TD]
[TD="align: right"]£9,566,292</SPAN>[/TD]
[TD] [/TD]
[TD]3 - TFM/SECURITY 41333</SPAN>[/TD]
[TD="align: right"]£11,525</SPAN>[/TD]
[TD="align: right"]£79,921</SPAN>[/TD]
[TD="align: right"]£8,509,554</SPAN>[/TD]
[TD] [/TD]
[TD]4 - Historic Contracts 41333</SPAN>[/TD]
[TD="align: right"]-£2,736</SPAN>[/TD]
[TD="align: right"]-£2,736</SPAN>[/TD]
[TD="align: right"]£2,671</SPAN>[/TD]
[TD] [/TD]
[TD]5 - BUOHEAD (Commercial) 41333</SPAN>[/TD]
[TD="align: right"]-£52,113</SPAN>[/TD]
[TD="align: right"]-£52,509</SPAN>[/TD]
[TD="align: right"]-£65,480</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1 - National Accounts 41364</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]2 - Cleaning 41364</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]3 - TFM/SECURITY 41364</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]4 - Historic Contracts 41364</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]5 - BUOHEAD (Commercial) 41364</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1 - National Accounts 41394</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]2 - Cleaning 41394</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]3 - TFM/SECURITY 41394</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]4 - Historic Contracts 41394</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]5 - BUOHEAD (Commercial) 41394</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1 - National Accounts 41425</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]2 - Cleaning 41425</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]3 - TFM/SECURITY 41425</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]4 - Historic Contracts 41425</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]5 - BUOHEAD (Commercial) 41425</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1 - National Accounts 41455</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]2 - Cleaning 41455</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]3 - TFM/SECURITY 41455</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]4 - Historic Contracts 41455</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]5 - BUOHEAD (Commercial) 41455</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1 - National Accounts 41486</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]2 - Cleaning 41486</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]3 - TFM/SECURITY 41486</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]4 - Historic Contracts 41486</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]5 - BUOHEAD (Commercial) 41486</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1 - National Accounts 41517</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]2 - Cleaning 41517</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]3 - TFM/SECURITY 41517</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]4 - Historic Contracts 41517</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]5 - BUOHEAD (Commercial) 41517</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1 - National Accounts 41547</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]2 - Cleaning 41547</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]3 - TFM/SECURITY 41547</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]4 - Historic Contracts 41547</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]5 - BUOHEAD (Commercial) 41547</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1 - National Accounts 41578</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]2 - Cleaning 41578</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]3 - TFM/SECURITY 41578</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]4 - Historic Contracts 41578</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]5 - BUOHEAD (Commercial) 41578</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1 - National Accounts 41608</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]2 - Cleaning 41608</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]3 - TFM/SECURITY 41608</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]4 - Historic Contracts 41608</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD]5 - BUOHEAD (Commercial) 41608</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1 - National Accounts 41639</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]2 - Cleaning 41639</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]3 - TFM/SECURITY 41639</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]4 - Historic Contracts 41639</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]5 - BUOHEAD (Commercial) 41639</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
</TBODY><COLGROUP><COL><COL><COL><COL><COL><COL><COL span=2><COL><COL><COL><COL><COL><COL><COL><COL><COL span=2><COL><COL><COL><COL span=2><COL><COL></COLGROUP>[/TABLE]








Code:
Sub CustomSumIf()
Dim lastGrpRow, grpNum As Integer
Dim sumGrp As Long
Dim firstAddress As String
Dim g As Range
 lastGrpRow = Sheets("DATA Capture").Range("B" & Rows.Count).End(xlUp).Row
   For grpNum = 5 To lastGrpRow
     With Sheets("Raw Data").Columns("A")
      Set g = .Find(Sheets("Data Capture").Range("B" & grpNum), lookat:=xlWhole)
        If Not g Is Nothing Then
          firstAddress = g.Address
            Do
              sumGrp = sumGrp + Sheets("Raw data").Range("AS" & g.Row)
              Set g = .FindNext(g)
            Loop While Not g Is Nothing And g.Address <> firstAddress
        End If
       Sheets("Data Capture").Range("c" & grpNum) = sumGrp
       sumGrp = 0
     End With
   Next
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

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