VBA Code numbering Cross Reference

khikha1

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

please need your help with a VBA code to find cross references and number them. i add a colors to explain my need. the code should take an item from column A and look in column B and C if it finds a reference for it it has to search column A again , if it find it or find them ,the code is to number them is column D. ( 1,2, ......) , if there is no Cross reference the cell in column D is to be Empty .
hope the attached picture is clear .
i really appreciate your help with this code as i am in real need for it .

regards
ziad alsayed .
 

Attachments

  • VBA Code.png
    VBA Code.png
    24 KB · Views: 14
dear plettieri

please need your assistance
i found this code and problem sorted out , thanks again

Sub UnifyItems()
Dim lastRow As Long
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
Dim currentItem As String
Dim itemCounter As Integer
itemCounter = 1
Dim i As Long
For i = 2 To lastRow
If Cells(i, 2) <> "" Then
currentItem = Cells(i, 2)
ElseIf Cells(i, 3) <> "" Then
currentItem = Cells(i, 3)
Else
currentItem = Cells(i, 1)
End If
If currentItem <> "" Then
Dim j As Long
For j = 2 To lastRow
If Cells(j, 1) = currentItem Or Cells(j, 2) = currentItem Or Cells(j, 3) = currentItem Then
Cells(j, 4).Value = itemCounter
End If
Next j
itemCounter = itemCounter + 1
End If
Next i
End Sub
 
Upvote 0
Solution

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

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