Countif with wildcard and cell reference

stapuff

Well-known Member
Joined
Feb 19, 2004
Messages
1,126
I am currently using the following formula, but need to expand the formula more

=COUNTIF(OnHand!$A$2:$A$20000,C2&E2)

I only want to look at the first 8 characters of the cells on sheet OnHand!$A$2:$A$20000 using character position 1,2,3,5,7,8 of the criteria C2&E2


Example

C2&E2 = SC123456

OnHand
A2 SC123456
A3 SC123456-01
A4 SC1X3B56
A5 SC1X3B56-01
A6 SC112256
A7 SC112256-02
A8 SC1Z3Z56-123
A9 SC1Z3Z56-456
A10 SC234567

The count formula would return 6 since A2,A3,A4,A5,A8,A9 all would meet the criteria

Any thoughts on how to accomplish this would be greatly appreciated.

stapuff
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
is this what you are looking for ?
Excel Workbook
ABCDE
2SC123456SC123456
3SC123456-01
4SC1X3B56
5SC1X3B56-012
6SC112256
7SC112256-02
8SC1Z3Z56-123
9SC1Z3Z56-456
10SC234567
OnHand
Excel 2007
Cell Formulas
RangeFormula
D5=SUMPRODUCT(--(LEFT(A2:A10,8)=C2&E2))
 
Upvote 0
Mike -

I do not understand your response. I do reference needing to use wildcards, but only specific locations not using the *, but using the ?

To accomplish my task I have done the following:

In column B of sheet OnHand I added a helped formula:
=LEFT(TRIM(A2),8) which returns just the left 8

In my main sheet in column D I added a helper column with the following formula in it:
=C2&LEFT(E2,1)&"?"&MID(E2,3,1)&"?"&MID(E2,5,2)

which returns SC1?3?56

then do the countif
=COUNTIF(OnHand!$B$2:$B$20000,D2) returns 6

This is ugly and far more than I wanted, but it works. Any suggestions on how to make it better?

stapuff
 
Upvote 0
I have been able to remove the helper column on the the main sheet and changed my formula to:

=COUNTIF(OnHand!$B$2:$B$20000,C2&LEFT(E2,1)&"?"&MID(E2,3,1)&"?"&MID(E2,5,2))

I would like to get rid of the helper column on sheet OnHand.

Any suggestions would be greatly appreciated.

Yahya - I did try your suggestion and several variations and all returned 0, which is not correct.

Thanks,

stapuff
 
Upvote 0
I did...in my first post.


Example

countif SC1?3?56

sheet OnHand with range
A2 SC123456
A3 SC123456-01
A4 SC1X3B56
A5 SC1X3B56-01
A6 SC112256
A7 SC112256-02
A8 SC1Z3Z56-123
A9 SC1Z3Z56-456
A10 SC234567

returns 6
 
Upvote 0
I just read "SumProduct requires numeric arrays/ranges"

so using something like this formula returns 0 because the use of "?" for wildcards must be viewed as text by the sumproduct function

=SUMPRODUCT(--(LEFT(OnHand!A2:A10,8)=C2&LEFT(E2,1)&"?"&MID(E2,3,1)&"?"&MID(E2,5,2)))

stapuff
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,704
Members
452,938
Latest member
babeneker

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