Countif problem

Nabei

New Member
Joined
Sep 3, 2014
Messages
7
Hi there

currently facing a countif problem. Below is my sample data

45001245-1
45001245-2
45001245-3

45001248-1
45001248-2

For the duplicate data i.e. 45001245-1, -2, -3, i would like to set the data ending with -1 to value 1 and the rest to value 0

Currently using this formula
=IF(Countif(A$2:A$15,A2)=1,1,0) without the implementation of the dashes as it wouldnt work if the data has dashes.

Any help is appreciated.
Thanks in advance
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Marcelo Branco

MrExcel MVP
Joined
Aug 23, 2010
Messages
17,100
Office Version
  1. 365
  2. 2016
  3. 2010
Platform
  1. Windows
Maybe...


A
B
1
2
45001245-1​
1​
3
45001245-2​
0​
4
45001245-3​
0​
5
6
45001248-1​
1​
7
45001248-2​
0​

Formula in B2 copied down
=IF(A2="","",--(COUNTIF(A$2:A2,LEFT(A2,SEARCH("-",A2)-1)&"*")=1))

Hope this helps

M.
 
Upvote 0

mfexcel

Well-known Member
Joined
Jan 8, 2009
Messages
791
ADVERTISEMENT
You may try the following if you always have "-??" in the end

=IF(RIGHT(A1,2)="-1",SUBSTITUTE(A1,"-",""),REPLACE(A1,FIND("-",A1),9,0))



do you data always contain only "-"?
 
Upvote 0

Marcelo Branco

MrExcel MVP
Joined
Aug 23, 2010
Messages
17,100
Office Version
  1. 365
  2. 2016
  3. 2010
Platform
  1. Windows
ADVERTISEMENT
A combination of "-" and without. Sorry for not mentioning earlier

Hadn't seen this post...

Maybe...


A
B
1
2
45001245-1​
1​
3
45001245-2​
0​
4
45001245-3​
0​
5
6
45001248-1​
1​
7
45001248-2​
0​
8
12345​
1​
9
12345​
0​
10
AB456​
1​
11
AB456​
0​

Formula in B2 copied down
=IF(A2="","",--(COUNTIF(A$2:A2,IF(ISNUMBER(A2),A2,LEFT(A2,IFERROR(SEARCH("-",A2)-1,LEN(A2)))&"*"))=1))

M.
 
Upvote 0

Nabei

New Member
Joined
Sep 3, 2014
Messages
7
Hi, thanks for your solution.

So i meddled a bit with it.

If the data is switched around, i.e

45001245-3
45001245-1
45001245-2

the data which ends with "-3" returns a value 1 instead of 0 while the data which ends with "-1" returns a value 0
 
Upvote 0

Nabei

New Member
Joined
Sep 3, 2014
Messages
7
Set a count for the data such that those that ends with "-1" (45001246-1) return a value of 1, and the rest (45001246-2, 45001246-3, 45001246-3) return a value of 0. hope that clarifies things
 
Upvote 0

Forum statistics

Threads
1,195,644
Messages
6,010,893
Members
441,571
Latest member
stolenweasel

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
Top