List unique numbers within ranges

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,422
Office Version
  1. 2010
Using Excel 2010
Hello,

I need VBA which find the unique numbers from the list of 1 to 35 numbers. Check within the rows 5 in 5.

Here is an example…

1st starting ranges C6:G10, (list Unique of 1 to 35 numbers) in the Cell J10 to right
2nd starting ranges C7:G11, (list Unique of 1 to 35 numbers) in the Cell J11 to right
3rd starting ranges C8:G12, (list Unique of 1 to 35 numbers) in the Cell J12 to right
And so on till end of the data……

Example sheet attached

Find Unique.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQAR
1
2
3
4
5n1n2n3n4n51234567891011121314151617181920212223242526272829303132333435
627282213
72420112312
8111828129
9969178
102211247261st Unique From Range C6:G10-->126789111213171820222324262829
112021912202nd Unique From Range C7:G11-->16789111217182021222324262829
123016251443rd Unique From Range C8:G12-->146789111214161718202122242526282930
1341719309?
14225162518?
152123212535?
16212141220?
17722232918?
18171342221?
194917225?
2029132635?
21917736?
22
23
Find Unique


Regards,
Moti
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
This should do the job, please note that your data appears to be incorrect. In the range C6:G10 you were saying that 7, 9, 11 were unique, however there were more than 1 instance of them in that range.
VBA Code:
Sub motilulla()
Dim Strtrng As Integer, edrng As Integer, uniq As Integer, i As Integer, col As Integer
Dim lr As Long
lr = Cells(Rows.count, "G").End(xlUp).Row
Strtrng = 6
edrng = 10
col = 10
For A = edrng To lr
    For i = 1 To 35
        uniq = Application.WorksheetFunction.CountIf(Range("C" & Strtrng & ":G" & edrng), i)
        If uniq = 1 Then
            Cells(edrng, col).Value = i
            col = col + 1
            Else
        End If
    Next i
    col = 10
    Strtrng = Strtrng + 1
    edrng = edrng + 1
Next A
End Sub
 
Upvote 1
Solution
This should do the job, please note that your data appears to be incorrect. In the range C6:G10 you were saying that 7, 9, 11 were unique, however there were more than 1 instance of them in that range.
dermie_72, yes you are correct it is my fault I would have said I want to have listed of all numbers are in the range (either they are unique or duplicate) please can you modify it. Thank you for your help.

Kind Regards,
Moti
 
Upvote 0
if you change this piece of code:
If uniq = 1 Then
to
If uniq <> 0 Then

then it will capture every number in the range and populate the field
 
Upvote 1
if you change this piece of code:
If uniq = 1 Then
to
If uniq <> 0 Then

then it will capture every number in the range and populate the field
dermie_72, thank you, yes changing the code as you suggest it list all numbers correctly. (y)

Have an awesome weekend! And Good Luck.

Kind Regards,
Moti :)
 
Upvote 1

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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