Excel VBA Highlight Duplicates and Duplicate between Range

decent_boy

Board Regular
Joined
Dec 5, 2014
Messages
130
Office Version
  1. 2016
Platform
  1. Windows
I need a VBA solution to highlight duplicate numbers and duplicate between range.

Book5
CDE
1NumbersRemarksDuplication
2123451 Duplication
323456This number is duplicated between C6 Cell2 Duplication
432456
5123451 Duplication
623455-23458Total Duplicated in this range 3
723457This number is duplicated between C6 Cell3 Duplication
834567
923455This number is duplicated between C6 Cell3 Duplication
Sheet1
 
Can anybody please reply that is it possible this kind of highlighting or should i need to explain it more
 
Upvote 0
This will convert the ranges into numbers, if you don't want that then don't use this script. Use at your own discretion.

VBA Code:
Sub text_to_number()
        
        Dim k, i, j As Integer
        Dim lr, lr2 As Long
        Dim container() As String
        Dim storage As String
        lr = Cells(Rows.Count, 1).End(xlUp).Row
        
        For k = lr To 2 Step -1
        
                If WorksheetFunction.IsText(Range("A" & k)) Then
                    
                  container = Split(Cells(k, 1), "-")
                  
                  string1 = container(0)
                  string2 = container(1)
                  
                  Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) = string1
                        j = 1
                  Do Until storage = string2
                        storage = string1 + j
                        Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) = storage
                        j = j + 1
                  Loop
                  Cells(k, 1).EntireRow.Delete
                  End If
                  
    Next k
    
    Call text_to_number2

End Sub

VBA Code:
Sub text_to_number2()
                
        Dim k As Integer
        Dim lr As Long
        
        lr = Cells(Rows.Count, 1).End(xlUp).Row
        For k = 2 To lr
        If WorksheetFunction.CountIf(Range("A2:A" & lr), Range("A" & k)) > 1 Then
            Range("A" & k).Interior.Color = vbYellow
        End If
        Next k

End Sub
 

Attachments

  • 1671370933391.png
    1671370933391.png
    21.3 KB · Views: 6
Upvote 0
Hi shinigamilight,
Thanks for you reply , but I want it to be highlighted and given duplication count as I mentioned in above example.
It is just like a challenging work
 
Upvote 0

Forum statistics

Threads
1,226,771
Messages
6,192,918
Members
453,766
Latest member
Gskier

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