Looking for dups numbers in groups of numbers in single column

JTL9161

Well-known Member
Joined
Aug 29, 2012
Messages
591
Office Version
  1. 365
Platform
  1. Windows
I have a column of numbers. I watered them down for this example below.

I am looking for a macro that will search EACH GROUP of numbers and find any dups. If there are none then go on to the next group and so on. I am not trying to find dup numbers in the entire column, just in each group.

After it finds a dupe I need it to note in a previous column.

The group size will be larger and vary in size but there should be at least 1 empty line between each grouping.

I've tried the macro's that look at the entire column but nothing seems to work for what I need.

Thanks for your help
James


<colgroup><col style="width:48pt" span="2" width="64"> </colgroup><tbody>
[TD="class: xl63, width: 64"] [/TD]
[TD="class: xl63, width: 64"] [/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63, align: right"]26[/TD]

[TD="class: xl63"]Dupe[/TD]
[TD="class: xl63, align: right"]34[/TD]

[TD="class: xl63"]Dupe[/TD]
[TD="class: xl63, align: right"]34[/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63, align: right"]42[/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63"] [/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63"] [/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63, align: right"]9[/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63, align: right"]15[/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63, align: right"]17[/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63, align: right"]22[/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63, align: right"]22[/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63"] [/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63"] [/TD]

[TD="class: xl63"]Dupe[/TD]
[TD="class: xl63, align: right"]2[/TD]

[TD="class: xl63"]Dupe[/TD]
[TD="class: xl63, align: right"]2[/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63, align: right"]13[/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63, align: right"]14[/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63, align: right"]49[/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63"] [/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63"] [/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63, align: right"]2[/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63, align: right"]6[/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63, align: right"]14[/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63, align: right"]21[/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63, align: right"]28[/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63"] [/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63"] [/TD]

[TD="class: xl63"]Dupe[/TD]
[TD="class: xl63, align: right"]1[/TD]

[TD="class: xl63"]Dupe[/TD]
[TD="class: xl63, align: right"]1[/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63, align: right"]8[/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63, align: right"]11[/TD]

[TD="class: xl63"] [/TD]
[TD="class: xl63, align: right"]24



[/TD]

</tbody>
 
Again Thanks for you help.

Getting back to it today. In my effort to simplify I only gave you 3 columns for the data. There is actually several columns in-between the data (duped numbers) and the letters. My letters are in column "B" and my possible duped numbers are in column "Z"

I tried tweaking your code above changing the Columns (3) to (25) thinking that is how many columns there are. Got the error "No Cells were found"

How would I tweak the above to compensate for the columns in-between using this setup

Letters (a,b,c..etc) are in Column "B" Possible Duped numbers are in column "Z" and I need the word "dupe" to show up in column "C"

Thanks again.
James
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Ok, try
Code:
Sub FindDupe()

    Dim ar As Areas
    Dim rng As Range
    Dim Cl As Range
    Dim Val As String
    
    Set ar = Columns(26).SpecialCells(xlConstants).Areas
    For Each rng In ar
        Val = ""
        For Each Cl In rng
            If WorksheetFunction.CountIf(rng, Cl) > 1 Then
                Cl.Offset(, -23).Value = "Dupe"
                If Val = "" Then
                    Val = Cl.Offset(, -24).Value
                Else
                    Cl.Offset(, -24).Value = Val
                End If
            End If
        Next Cl
    Next rng

End Sub
 
Upvote 0
You are incredible! Almost there. Of course I didn't give you all the parameters so I'm back.

Within the A, B, C, D...etc there could be numbers (as text) 1. 99. 76. etc. After your code runs when it goes to copy the above line (column A) it does not copy it as text. Meaning:

A 889
B 876
99. 999
97. 999

Comes out like:

A 889
B 876
99. Dupe 999
99 Dupe 999

Any way to correct that? So the "." is also copied. Not a biggie but just want to keep everything the same till I manually edit it.

Also had this:
W 99
X 99
G 77
H 77

Come out like this:

W Dupe 99
W Dupe 99
W Dupe 77
W Dupe 77

when it should have came out like this
W Dupe 99
W Dupe 99
G Dupe 77
G Dupe 77

It needs to tell when a new set of dupes is found. Not sure how often this will happen but if its fixable that would be one less thing to worry about.


Thank you, thank you
James
 
Upvote 0
Give this a go
Code:
Sub FindDupe()

    Dim Ar As Areas
    Dim rng As Range
    Dim Cl As Range
    Dim Val As String
    
    Set Ar = Columns(26).SpecialCells(xlConstants).Areas
    For Each rng In Ar
        Val = ""
        For Each Cl In rng
            If WorksheetFunction.CountIf(rng, Cl) > 1 Then
                Cl.Offset(, -23).Value = "Dupe"
                If Val = "" Then
                    Val = Cl.Offset(, -24).Value
                Else
                    Cl.Offset(, -24).Value = "'" & Val
                    Val = ""
                End If
            End If
        Next Cl
    Next rng

End Sub
 
Upvote 0
Great again! Just one more thing and I think you can get rid of me.

When there are 3 dups it doesn't copy the data in column "A" all the way down.

For example:


A 999
B 999
C 999
D 897
E 555

Comes out as:

A DUPE 999
A DUPE 999
C DUPE 999
D 897
E 555

In this case there is a third dupe so the A has to come down and overlay the "C". I don't think this will happen much, same a 4 dupes and the "D" would need to be an "A"


Thanks again,
James
 
Upvote 0
How about
Code:
Sub FindDupe()

    Dim Ar As Areas
    Dim Rng As Range
    Dim Cl As Range
    Dim Val As String
    
    Set Ar = Columns(26).SpecialCells(xlConstants).Areas
    For Each Rng In Ar
        Val = ""
        For Each Cl In Rng
            If WorksheetFunction.CountIf(Rng, Cl) > 1 Then
                Cl.Offset(, -23).Value = "Dupe"
                If Cl.Value = Cl.Offset(-1).Value Then
                    Cl.Offset(, -24).Value = "'" & Cl.Offset(-1, -24).Value
                End If
            End If
        Next Cl
    Next Rng

End Sub
 
Upvote 0
Bingo!

I still need to try it on a much larger file but it should be good! I am only trying it on a 100 line spreadsheet now. I will check on a larger one.

While I still have you. Totally separate code.

Select 1 column only. (for example: "D")

Search for "0" (zero's) Match entire cell contents

When a "0" is found. Go 1 row up and copy that cell down 1 row.


So like this:

D1 5
D2 0
D3 16
D4 10
D5 11
D6 0
D7 20

I would need it to copy the "5" in cell D1 over the "0" in D2. Then search for the next "0" and copy the "11" in cell D5 over the "0" in D6. Then when there are no more "0" have a msgbox come up saying "no more zero's"


Thanks
James
 
Upvote 0
One option would be
Code:
Sub chk()
    With Range("D2", Range("D" & Rows.Count).End(xlUp))
        .Value = Evaluate("if(" & .Address & "=0," & .Offset(-1).Address & "," & .Address & ")")
    End With
    MsgBox "Done"
End Sub
But if you are likely to have 2 consecutive rows with a 0, this won't work.
 
Upvote 0
Thanks. I will give it a try. Not as important as the DUPE one.

If you don't mind I will keep this link so if I have any other questions in the future I can contact you.


Thank you for your help.
James
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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