VBA Code Found duplicates in Two Columns in number them

khikha1

New Member
Joined
Jun 10, 2020
Messages
22
Office Version
  1. 365
Platform
  1. Windows
dear all

long time , hope this finds you well ,
please need your help with a VBA code to find duplicates , i have sheet of two columns , the first is item numbers and the second is description with numbers.
as per attached pictures i highlighted some items with same colors in columns A that i found in column B , e.g colour blue , the second item is found in column B so i highlited both in Blue and put in column C same number for them and so on...
would like a VBA code to so this please
thanks in advance .

regards
Ziad alsayed.
 

Attachments

  • Mr Excel VBA Code.png
    Mr Excel VBA Code.png
    32.7 KB · Views: 36

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
dear all

long time , hope this finds you well ,
please need your help with a VBA code to find duplicates , i have sheet of two columns , the first is item numbers and the second is description with numbers.
as per attached pictures i highlighted some items with same colors in columns A that i found in column B , e.g colour blue , the second item is found in column B so i highlighted both in Blue and put in column C same number for them and so on...
would like a VBA code to so this please
thanks in advance .

regards
Ziad alsayed.
dear all

please need your assistance with this .
thanks in advance

regards
Ziad alsayed
 
Upvote 0
@khikha1 if your data set is not too large then maybe this will do the numbering/

VBA Code:
Sub Ziad()
Dim Arng As Range
Dim Brng As Range
Dim Num As Long
Dim lr As Long
Dim Inc As Boolean
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
lr = Range("A" & Rows.Count).End(xlUp).Row
Num = 1
Set Arng = Range("A2:A" & lr)
Set Brng = Range("B2:B" & lr)
For Each Acell In Arng
If Inc = True Then
Num = Num + 1
Inc = False
End If
    For Each Bcell In Brng
        If InStr(Bcell, Acell) Then
        Inc = True
        Acell.Offset(0, 2) = Num
        Bcell.Offset(0, 1) = Num
        Exit For  '<<*********  Delete ithis line if there may be MORE that just 1 matching per number in A
        End If
    Next Bcell
    
Next Acell
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True


End Sub
 
Upvote 0
Solution
th
@khikha1 if your data set is not too large then maybe this will do the numbering/

VBA Code:
Sub Ziad()
Dim Arng As Range
Dim Brng As Range
Dim Num As Long
Dim lr As Long
Dim Inc As Boolean
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
lr = Range("A" & Rows.Count).End(xlUp).Row
Num = 1
Set Arng = Range("A2:A" & lr)
Set Brng = Range("B2:B" & lr)
For Each Acell In Arng
If Inc = True Then
Num = Num + 1
Inc = False
End If
    For Each Bcell In Brng
        If InStr(Bcell, Acell) Then
        Inc = True
        Acell.Offset(0, 2) = Num
        Bcell.Offset(0, 1) = Num
        Exit For  '<<*********  Delete ithis line if there may be MORE that just 1 matching per number in A
        End If
    Next Bcell
   
Next Acell
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True


End Sub
thank you , it is working perfectly .
 
Upvote 0
thank you , it is working perfectly .

The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,223,948
Messages
6,175,571
Members
452,652
Latest member
eduedu

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