SUMIFS criteria 1st through 3rd digits =??

jkream

New Member
Joined
Jul 14, 2016
Messages
10
I am writing a macro to return the sum of the amounts in a column C (CHECK_AMT) when the criteria in column B are met. I am having trouble differentiating the column B (FILENO) results:

[TABLE="width: 149"]
<tbody>[TR]
[TD]FILENO[/TD]
[TD]CHECK_AMT[/TD]
[/TR]
[TR]
[TD]100X2943[/TD]
[TD="align: right"]175[/TD]
[/TR]
[TR]
[TD]100X3076[/TD]
[TD="align: right"]200[/TD]
[/TR]
[TR]
[TD]100X692[/TD]
[TD="align: right"]25[/TD]
[/TR]
[TR]
[TD]11BB47[/TD]
[TD="align: right"]25[/TD]
[/TR]
[TR]
[TD]1B1083[/TD]
[TD="align: right"]150[/TD]
[/TR]
[TR]
[TD]1B1266[/TD]
[TD="align: right"]25[/TD]
[/TR]
[TR]
[TD]1B992[/TD]
[TD="align: right"]10[/TD]
[/TR]
[TR]
[TD]227X9[/TD]
[TD="align: right"]617[/TD]
[/TR]
[TR]
[TD]24X108[/TD]
[TD="align: right"]20[/TD]
[/TR]
[TR]
[TD]336X1301[/TD]
[TD="align: right"]150[/TD]
[/TR]
[TR]
[TD]336X1683[/TD]
[TD="align: right"]250[/TD]
[/TR]
[TR]
[TD]336X2037[/TD]
[TD="align: right"]100[/TD]
[/TR]
[TR]
[TD]362X12[/TD]
[TD="align: right"]75[/TD]
[/TR]
[TR]
[TD]369X1549[/TD]
[TD="align: right"]50[/TD]
[/TR]
[TR]
[TD]369X2442[/TD]
[TD="align: right"]50[/TD]
[/TR]
[TR]
[TD]425A2993[/TD]
[TD="align: right"]100[/TD]
[/TR]
[TR]
[TD]425A3090[/TD]
[TD="align: right"]200[/TD]
[/TR]
[TR]
[TD]425A3202[/TD]
[TD="align: right"]50[/TD]
[/TR]
[TR]
[TD]425B272[/TD]
[TD="align: right"]25[/TD]
[/TR]
[TR]
[TD]4AA4294[/TD]
[TD="align: right"]50[/TD]
[/TR]
[TR]
[TD]4AA1868[/TD]
[TD="align: right"]150[/TD]
[/TR]
[TR]
[TD]4AA2367[/TD]
[TD="align: right"]50[/TD]
[/TR]
[TR]
[TD]4BB1289[/TD]
[TD="align: right"]500[/TD]
[/TR]
[TR]
[TD]4BB1326[/TD]
[TD="align: right"]50[/TD]
[/TR]
[TR]
[TD]4CC1115[/TD]
[TD="align: right"]10[/TD]
[/TR]
[TR]
[TD]4CC1376[/TD]
[TD="align: right"]50[/TD]
[/TR]
[TR]
[TD]4CC1456[/TD]
[TD="align: right"]125[/TD]
[/TR]
[TR]
[TD]4CC912[/TD]
[TD="align: right"]250[/TD]
[/TR]
[TR]
[TD]4DD135[/TD]
[TD="align: right"]40[/TD]
[/TR]
[TR]
[TD]4DD1612[/TD]
[TD="align: right"]50[/TD]
[/TR]
[TR]
[TD]4DD279[/TD]
[TD="align: right"]25[/TD]
[/TR]
[TR]
[TD]4DD536[/TD]
[TD="align: right"]12.5[/TD]
[/TR]
[TR]
[TD]4DD545[/TD]
[TD="align: right"]25[/TD]
[/TR]
[TR]
[TD]4DD999[/TD]
[TD="align: right"]65[/TD]
[/TR]
[TR]
[TD]4Z206[/TD]
[TD="align: right"]50[/TD]
[/TR]
[TR]
[TD]4Z75[/TD]
[TD="align: right"]80[/TD]
[/TR]
[TR]
[TD]4Z76[/TD]
[TD="align: right"]80[/TD]
[/TR]
[TR]
[TD]900G1161[/TD]
[TD="align: right"]20[/TD]
[/TR]
[TR]
[TD]900G1259[/TD]
[TD="align: right"]40[/TD]
[/TR]
[TR]
[TD]900G18[/TD]
[TD="align: right"]30[/TD]
[/TR]
[TR]
[TD]90X37[/TD]
[TD="align: right"]50[/TD]
[/TR]
</tbody>[/TABLE]

The first set of numbers in the file number is the client, the rest is useless. I need to sum by client. The number of rows will be variable, so I would like to select ALL of rows in each column without hard coding the range.
ie: I need to sum all the values if the file number begins with ONLY a 4, NOT 426 or 425, or 90, but NOT 900, 1,11, and 100 are all to be separate.
For this I am only summing the 4's and the 900's but show me once and I can expand on it if I need to.
I am writing this in Excel 2013, but one of my users is running 2003 and it has to be compatible.
This is my first attempt at VB Macros. Any help is appreciated.
 
Oh sorry I forgot a part, you have to change the length for LEFT to accommodate the length of the number

Code:
Range("K4").Formula = "=SUMPRODUCT(--(LEFT(A1:A" & x & ",2)=""90""),1-(ISNUMBER(MID(A1:A" & x & ",3,1)+0)),B1:B" & x & ")"
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Oh sorry I forgot a part, you have to change the length for LEFT to accommodate the length of the number

Code:
Range("K4").Formula = "=SUMPRODUCT(--(LEFT(A1:A" & x & ",2)=""90""),1-(ISNUMBER(MID(A1:A" & x & ",3,1)+0)),B1:B" & x & ")"

This is Awesome, thank you so much for your effort.
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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