Only use data from certain headers/categories/groups

wesleyterrill

New Member
Joined
Feb 9, 2016
Messages
15
Hello, everyone!

Every day, I use several reports that look like the table below (I can export as csv or xlsx.) I need to be able to pull data only from certain headers - specifically all 1900 and 3900 groups. (In my actual data, that will include 1901, 1902, 1903, etc.) But I need to exclude the 2900 categories.

What would be the best way to go about this? If the formula were correct, it should add up the 1900 and 3900 totals: $575 (D4) + $95 (D8) + $450 (D17) + $350 (D20). Any help would be greatly appreciated!


A
BCD
11905 - Doors


2
Invoice #1
$250
3
Invoice #2
$325
4

Total$575
51945 - Windows


6
Invoice #3
$50
7
Invoice #4
$45
8

Total$95
92905 - Maintenance


10
Invoice #5
$25
11

Total$25
122975 - Repair


13
Invoice #6
$40
14

Total$40
153905 - Construction


16
Invoice #7
$450
17
Total$450
183925 - Equipment
19
Invoice #8
$350
20

Total$350

<tbody>
</tbody>
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
1905 - Doors 1905 - Doors19very easy to make a helper column
Invoice #1 2501905 - Doors19to put the col A titles on every relevant row
Invoice #2 3251905 - Doors19and to put the first two digits into a second helper column
Total5751905 - Doors1919670
1945 - Windows 1945 - Windows192965
Invoice #3 501945 - Windows1939800
Invoice #4 451945 - Windows19
Total951945 - Windows19
2905 - Maintenance 2905 - Maintenance29
Invoice #5 252905 - Maintenance29your dollar amounts appear to be text
Total252905 - Maintenance29
2975 - Repair 2975 - Repair29
Invoice #6 402975 - Repair29
Total402975 - Repair29
3905 - Construction 3905 - Construction39formula giving 670
Invoice #7 4503905 - Construction39=SUMPRODUCT(($C$1:$C$20="Total")*($D$1:$D$20)*($F$1:$F$20=H4))
Total4503905 - Construction39
3925 - Equipment 3925 - Equipment39
Invoice #8 3503925 - Equipment39
Total3503925 - Equipment39

<colgroup><col><col><col><col><col><col span="9"></colgroup><tbody>
</tbody>
 
Upvote 0
in E1
=LEFT(A1,4)

in E2
=IF(A2<>"",LEFT(A2,4),F1)
and copy E2 down the column

Column D needs to be numbers not text with a $, if you have $ remove the dollar sign unless that column is a number formatted with a $.

Then use this

=SUMPRODUCT(((E1:E20>1900)*(E1:E20<=1999))+((E1:E20>=3900)+(E1:E20<=3999))*(C1:C20<>"Total")*(D1:D20))

Total in your example should be 1535
 
Upvote 0
Hi,

als a starting point, result in the debug-window:

Code:
Sub Fen()
Cells(Rows.Count, 4).End(xlUp).Offset(1, -3) = "@"
For Each Ar In Columns(1).SpecialCells(2).Areas
    If InStr(1, "1939", Left(Ar.Cells(1), 2)) > 0 Then
        Debug.Print Ar.Row, Ar.End(xlDown).Offset(-1, 3)
    End If
Next Ar
End Sub

The should be a space-line before the first code.
 
Upvote 0
The total should be 1470. 575+95+450+350=1470. I need the 1900 AND 3900 groups.

Ideally, I'd like to just dump the raw data and have a formula pull the necessary info. Since my csv will be different every time, I don't want to create new columns for every report.

But I might have to go with this process, thanks!
 
Upvote 0
@Special-K99 - that's correct, but looking at your formula, I think we're really close.

I've been playing around with SUMIFS but I can't quite get it to work. I'm putting: =SUMIFS (D1:D20, C1:C20, "Total", E1:E20, >=1900, E1:E20, <=1999, E1:E20, >=3900, E1:E20, <=3999) but it isn't being accepted by Excel.

=SUMIFS (sum_range, range1, criteria1, [range2], [criteria2], ...)
 
Last edited:
Upvote 0
@oldbrewer what do you mean 10/10? Like they came out 100% correct?

Your method requires extra steps - I'm just worried that it can't be standardized for every report. How would you alter that formula to include the 3900 invoices as well? Ideally, I'll just plug in the data and have my total ($1470) instead of having to go back and add up all the totals I need.
 
Upvote 0
I calculated for all number groups - from that table you can make a new table with only your preferred groups - but I will go back and mod it for you....
 
Upvote 0

Similar threads

Forum statistics

Threads
1,215,223
Messages
6,123,714
Members
449,118
Latest member
MichealRed

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