Help with Counting Unique Duplicates

mandinko

New Member
Joined
Sep 17, 2014
Messages
24
Ok I will keep it simple with two rows. What I am trying to do is count unique duplicate values from one row into another row.

DateDraw1Draw2Draw3Draw4
9/16/20146979
9/15/20146193

<colgroup><col><col span="4"></colgroup><tbody>
</tbody>
I am trying to count the number of repeat digits that occurred in draw 9/15 to 9/16. I am stuck with this formula and it gives me 3 which should be 2. This is my current formula and I am stuck right now. Please note I want to count the unique digits. For example the 6 and 9 was drawn on September 15 but it also came up on 9/16 too but it is counting the 9 twice but it should be once.

=SUM(IFERROR(SUM(1/COUNTIF(B21:E21,B20)),0)+IFERROR(SUM(1/COUNTIF(B21:E21,C20)),0)+IFERROR(SUM(1/COUNTIF(B21:E21,D20)),0)+IFERROR(SUM(1/COUNTIF(B21:E21,E20)),0)
)

Any help would be greatly appreciated.

Thanks

Calvin
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
ok- so one more example- If the drawing was 1145 on 9/5 then on 9/6 drawing 1944, what should the output be?
 
Upvote 0
If the drawing was 1144 on 9/5 then on 9/6 drawing 1944, would the repeated digit total be 2?

That would be 3 repeats. The 144 repeated from the previous drawing

Instead of a formula i suggest a UDF (User Defined Function)

Code:
Function CountRep(r1 As Range, r2 As Range) As Long
    Dim strAux As String, rCell As Range
    
    strAux = r2(1) & r2(2) & r2(3) & r2(4)
    For Each rCell In r1
        If InStr(1, strAux, rCell) Then
            CountRep = CountRep + 1
            strAux = Application.Substitute(strAux, rCell, "", 1)
        End If
    Next rCell
    
End Function

Usage
Formula in F2
=CountRep(B2:E2,B3:E3)
copy down

M.
 
Last edited:
Upvote 0
Marcelo.

I am stuck on entering this code because you have a reference in the code CountRep and then you say enter in "F2" the formula which contains CountRep. Maybe I am doing something wrong because Excel will not allow me to save it as a Macro right now.. Thanks Calvin
 
Upvote 0
Marcelo.

I am stuck on entering this code because you have a reference in the code CountRep and then you say enter in "F2" the formula which contains CountRep. Maybe I am doing something wrong because Excel will not allow me to save it as a Macro right now.. Thanks Calvin

Try
Select the code in post #24 and copy (Ctrl+C)
Alt+F11 to open the VBEditor
Menu
Insert > Module
Paste (Ctrl+V) in the right panel

Back to Excel
Assuming your data setup as post #18
Select the cell F2 and insert the formula
=CountRep(B2:E2,B3:E3)
Copy down

M.
 
Upvote 0
Ok I think that fixed it. Wow thank you. I might need to send you a paypal. Send me your email address. Also one final thing. Should I save it with a macro or without a macro. I don't want to lose that code

Thanks,

Calvin
 
Upvote 0

Forum statistics

Threads
1,214,989
Messages
6,122,622
Members
449,093
Latest member
catterz66

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