Find duplicates to show in MsgBox

MagnusGrey

New Member
Joined
Mar 13, 2017
Messages
8
Hi All,

I have this problem for a while now, I'm trying to count the duplicates by the last 2 digits of data in 1 column using this formula "=0+(COUNTIF(R2C[-6]:R10000C[-6],RIGHT(RC[-6],2)&""*"")>1)" but it doesn't make the count.

What I'm trying to do is a macro that shows in a MsgBox the 2 digits number with their respective duplicate count for example
40 = 4
54 = 2

8546
9540
4540
4543
8054
5444
6254
9540
5440
5490
5435
5458
<colgroup><col width="64" style="width: 48pt;"> <tbody> </tbody>
 
@Marcelo-

You are right. The way I had extended the data there were no numbers that had single occurrences. I just added a few at the bottom and Fazza's code returned the number of occurrences for the newly added data as 1.

igold
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
whoops - i missed the requirement that only duplicates were to be returned.
Amended code below, also changed for situation of no duplicates
and format as "00"

Code:
Sub assumes_numeric_data()

  Const lCOLUMN_TO_ANALYSE As Long = 1 'column with the data


  Dim i As Long, k As Long
  Dim v As Long
  Dim ar() As Variant
  Dim input_data As Variant
  
  input_data = ActiveSheet.UsedRange.Columns(lCOLUMN_TO_ANALYSE).Value2
  ReDim ar(0 To 99)
  
  For i = LBound(input_data) To UBound(input_data)
    If Len(input_data(i, 1)) > 0 Then
      v = CLng(Right$(input_data(i, 1), 2))
      ar(v) = ar(v) + 1
    End If
  Next i
  
  For i = LBound(ar) To UBound(ar)
    If ar(i) > 1 Then 'CHANGED HERE SO ONLY COUNTS > 1 RETURNED
      ar(k) = Format$(i,"00") & " = " & ar(i)
      k = k + 1
    End If
  Next i
  
  'And changed below here to handle no duplicates
  If k > 0 Then
    ReDim Preserve ar(0 To k - 1)
    MsgBox Join$(ar, vbCr)
  Else
    MsgBox "no duplicates"
  End If


End Sub
 
Last edited:
Upvote 0
Wow thank you all!! I just review all codes and it worked like a charm, really appreciate the different ways to approach the goal!!
 
Upvote 0

Forum statistics

Threads
1,216,117
Messages
6,128,935
Members
449,480
Latest member
yesitisasport

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