kind of countif

M

Micos3

Hi!
I want to make a kind of countif, to ensures me that no number is repeated in a column. i have that column numbered in sequence, so i would like that once the 2 numbers be detected it would give me the row number of the 2.

Can someone help me?

Thanks
 
R

RagDyeR

This will give you the row number of the original number that was
duplicated.
Unique numbers will display a zero.

If your numbers are in column A starting in A1,
Enter this in B1:

=(COUNTIF(A:A,A1)>1)*(MATCH(A1,A:A,0))

Double click the "fill handle" to copy the formula down column B, as far as
there is data in column A.

If this doesn't do what you want, you can try Chip Pearson's web page that
has many other options concerning duplicates.

http://www.cpearson.com/excel/duplicat.htm
--

HTH,

RD
==============================================
Please keep all correspondence within the Group, so all may benefit!
==============================================

Hi!
I want to make a kind of countif, to ensures me that no number is repeated
in a column. i have that column numbered in sequence, so i would like that
once the 2 numbers be detected it would give me the row number of the 2.

Can someone help me?

Thanks
 
B

Bob Phillips

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Micos3 said:
Hi!
I want to make a kind of countif, to ensures me that no number is repeated
in a column. i have that column numbered in sequence, so i would like that
once the 2 numbers be detected it would give me the row number of the 2.
 
B

Bob Phillips

Use conditional formatting using a formula of =COUNTIF($A$1:A1,A1)>1 and
set a colour to suit.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Micos3 said:
Hi!
I want to make a kind of countif, to ensures me that no number is repeated
in a column. i have that column numbered in sequence, so i would like that
once the 2 numbers be detected it would give me the row number of the 2.
 
M

Micos3

Thanks, your option really count the duplicates like options of page u gave me, but i guess i don't explain myself good.
ex.
A B
1 A3, A5
2
3 mario 11
4 joao 10
5 andre 11
As u can see i want cell A1 (ex.) give me the cell number where the repetitions are.
I think this is quite dificult cos it has to obey to comparing terms and then show result, but how to do this????? :)


"RagDyeR" escreveu:
 
M

Micos3

Doing with this formula is good,
=COUNTIF($A$1:A1,A1)>1,

Is there a way to after the 1º conditional format he passes to 2º cond.format with same condition, so we can change colours and in a way doing what i said cos i think we can count colours.


"Micos3" escreveu:
 
B

Bob Phillips

Not really sure what you are asking.

Do you want to change the colour each time a duplicate is found? If so, that
won't work with CF, you will need VBA.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Micos3 said:
Doing with this formula is good,
=COUNTIF($A$1:A1,A1)>1,

Is there a way to after the 1º conditional format he passes to 2º
cond.format with same condition, so we can change colours and in a way doing
what i said cos i think we can count colours.
 
A

AlfD

Hi!

Depends on how many colours you want. If 4 will do, then conditiona
formating using

formula is
1st condition:
=COUNTIF($B$2:$B$14,B2)=2 for entries appearing twice
2nd condition
=COUNTIF($B$2:$B$14,B2)=3 for entries appearing 3 times
3rd condition
=COUNTIF($B$2:$B$14,B2)>3 for entries appearing more than 3 times

together with no colour for entries appearing just once

might help.

Otherwise: can you sort the table? This would bring all duplicate
together in groups. Since you have all of your rows numbered, you woul
be able to re-sort them again.

Al
 
M

Micos3

I'll try explain again :)
This example shows what i inteted to do:
A B
1 A3, A5
2
3 mario 11
4 joao 10
5 andre 11
I want cell A1 (ex.) give me the where the repetitions are.

Then after see ur advices i saw that this is look like impossible, so it seems to me that the option colour is more easier to do, so what i was pretending was, that when a value of cell was equal to other in same row, those two would became in same colour, taking example up.

A B

3 mario 11 (gren)
4 joao 10 (red)
5 andre 11 (gren)
6 nuno 9
7 maria 10 (red)
8 ana 10 (red)

I guess now is better explained, i have all equals have same colour, i hope r few so 3, 4 conditions will do.
Thanks all for helping me in this crazy :)


"AlfD >" escreveu:
 
B

Bob Phillips

Surely, the whole point of his question is that he would have no idea how
many times it would change, therefore how many colours he would need. Using
CF under those circumstances would be dangerous and asking for a failure.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
B

Bob Phillips

Still can't use conditional formatting as you would know which to colour
green, which red, etc.

This code does it

Sub ColourThem()
Dim i As Long
Dim crows As Long
Dim dicColours
Dim iColour As Long
Dim cColour As Long

Set dicColours = CreateObject("Scripting.Dictionary")
aryColours = Array(10, 3, 6, 34, 19, 5) ' add more if needed
crows = Cells(Rows.Count, "B").End(xlUp).Row
For i = 1 To crows
If WorksheetFunction.CountIf(Range("B:B"), Range("B" & i)) > 1 Then
If dicColours.exists(CStr(Cells(i, "B").Value)) Then
iColour = dicColours.Item(CStr(Cells(i, "B").Value))
Else
iColour = aryColours(cColour)
cColour = cColour + 1
dicColours.Add CStr(Cells(i, "B")), iColour
End If
Cells(i, "B").Interior.ColorIndex = iColour
End If
Next i
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Micos3 said:
I'll try explain again :)
This example shows what i inteted to do:
A B
1 A3, A5
2
3 mario 11
4 joao 10
5 andre 11
I want cell A1 (ex.) give me the where the repetitions are.

Then after see ur advices i saw that this is look like impossible, so it
seems to me that the option colour is more easier to do, so what i was
pretending was, that when a value of cell was equal to other in same row,
those two would became in same colour, taking example up.
A B

3 mario 11 (gren)
4 joao 10 (red)
5 andre 11 (gren)
6 nuno 9
7 maria 10 (red)
8 ana 10 (red)

I guess now is better explained, i have all equals have same colour, i
hope r few so 3, 4 conditions will do.
 
A

AlfD

Hi Bob!

But you're still left with the "add more if necessary" stricture on th
colour matrix.

I was thinking more of an iterative process: deal with the 2's and 3'
(OP's aim is to eliminate them). Then break the over 3's into 4's, 5'
and over 5's etc.

However, I still have a feeling that either Data >Sort or Dat
Subtotals could be a better way - in the spirit of KIS.

Alternatively, I would think your sub could be engineered to do th
original job (naming the offending cells) rather than colouring the
and then leaving the job of dealing with the colours (visually o
programatically) still to be done.

Al
 
B

Bob Phillips

Hi yourself Alf,

AlfD > said:
However, I still have a feeling that either Data >Sort or Data

Amen to that. This clearly seems like a case where a proper requirements
definition would serve a better design, rather than the poster telling us
what he wants to code.
Alternatively, I would think your sub could be engineered to do the
original job (naming the offending cells) rather than colouring them
and then leaving the job of dealing with the colours (visually or
programatically) still to be done.

I provided a code solution, which works as far as I can tell, and you are
probably correct it could be modified to meet his original ask, but it's
still a mess and I am not sure it would be the best solution he could get.
 
M

Micos3

Thanks for all this effort!
The program isn't working in my pc, do u know why?
Thanks again

Portuguese Saudations
"The Braves may not win, but they still Braves"

"Bob Phillips" escreveu:
 
Top