COUNTIF and Partial text arrays

jpfuse

New Member
Joined
Jan 19, 2010
Messages
15
I'm a bit new at using arrays in excel formulas. I need to check for duplicates in a range of cells. The tricky part is i want to check just a part of the text in the cells. I started with the following:

A
1 HS
2 HS
3 LS
4 LS
5 TERT

I used the following formula: =IF(SUMPRODUCT((COUNTIF(A1:A5,A1:A5)>1)+0)>1,"Duplicates exist","NO Duplicates")
The next range of cells is what i need to lookup.

A
1 HS BKR 1
2 HS BKR 2
3 LS BKR 1
4 LS BKR 2
5 TERT

I want to check to see if there are more than one cell with "HS" or "LS" in it, regardless of what is after.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try...

=IF(SUMPRODUCT((COUNTIF(A1:A5,{"HS","LS"}&"*")>1)+0)>1,"Duplicates exist","NO Duplicates")
 
Upvote 0
Try...

=IF(SUMPRODUCT((COUNTIF(A1:A5,{"HS","LS"}&"*")>1)+0)>1,"Duplicates exist","NO Duplicates")
Not real sure what the OP is wanting to do...but...

With this data:

Book1
A
2HS BKR
3_
4LS BKR
5LS BKR
6TERT
Sheet2

That formula returns "No Duplicates".

The LS entry is a dupe.

Maybe something like this...

=IF(OR(COUNTIF(A2:A6,"HS*")>1,COUNTIF(A2:A6,"LS*")>1),"Duplicates","No Duplicates")
 
Upvote 0
Thanks Biff... That should have been...

=IF(SUMPRODUCT((COUNTIF(A1:A5,{"HS","LS"}&"*")>1)+0)>0,"Duplicates exist","NO Duplicates")
 
Upvote 0
With your list in A1:A5
this regular formula tests if there is more than 1 instance of text beginning with "HS" or "LS"...
Code:
B1: =IF(MAX(COUNTIF(A1:A5,{"HS*","LS*"}))>1,"Dupes","No dupes")
Does that help?
 
Upvote 0
wow, thanks guys. works great. it raises another questions for me though. originally i had tried to define a name which was an array of the first two letters of these rows. i would then use that name to compare with, but it kicked back some errors and i couldn't figure it out.

Here is the name:
_name = =LEFT('Data Entry'!A1:A5,2)
And then the formula:
=IF(SUMPRODUCT((COUNTIF(_name,_name)>1)+0)>1,"Duplicates exist","NO Duplicates")
This gives a #VALUE error and i can't figure out why.
 
Upvote 0
wow, thanks guys. works great. it raises another questions for me though. originally i had tried to define a name which was an array of the first two letters of these rows. i would then use that name to compare with, but it kicked back some errors and i couldn't figure it out.

Here is the name:
_name = =LEFT('Data Entry'!A1:A5,2)
And then the formula:
=IF(SUMPRODUCT((COUNTIF(_name,_name)>1)+0)>1,"Duplicates exist","NO Duplicates")
This gives a #VALUE error and i can't figure out why.
The COUNTIF function won't work with a defined name like that.
 
Upvote 0
The COUNTIF function only accepts a Range object as its first argument, not an array. Try something like this instead...

=IF(SUM(IF(FREQUENCY(IF(A1:A5<>"",MATCH(LEFT(A1:A5,2),LEFT(A1:A5,2),0)),ROW(A1:A5)-ROW(A1)+1)>1,1)),"Duplicates","No Duplicates")

...confirmed with CONTROL+SHIFT+ENTER.
 
Upvote 0
awww... ok... yeah i am still learning where i can and can't use arrays. they are very powerful tools to use, but there are definitely restrictions as to how they can be applied and manipulated. thanks again for everyone's input.
 
Upvote 0
awww... ok... yeah i am still learning where i can and can't use arrays. they are very powerful tools to use, but there are definitely restrictions as to how they can be applied and manipulated. thanks again for everyone's input.

Also, array formulas can take longer to calculate, and are not as efficient. For this reason, it may be better to use Biff's solution.
 
Upvote 0

Forum statistics

Threads
1,224,570
Messages
6,179,610
Members
452,931
Latest member
The Monk

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