RasGhul
Well-known Member
- Joined
- Jul 15, 2016
- Messages
- 797
- Office Version
- 365
- Platform
- Windows
I have the following code that compares part numbers from 2 sheets and updates them to the latest entry. This works very well for one fixed column(last entry). What I'm trying to achieve is updating the values from a specific column based on a cell value("aCell") which matches the headers from the target sheet. The header/find part of the code works but I don't know how to make the column number match the change in header value.(lastrowMS section, Cells(p, 8)).
Code:
Dim partNumber As String, specialPrice As String
Application.ScreenUpdating = False
Worksheets("QUOTE TEMPLATE").Activate
lastrowMR = Sheets("QUOTE TEMPLATE").Cells(Rows.Count, 1).End(xlUp).Row
For I = 18 To lastrowMR
partNumber = Cells(I, 2).Value
specialPrice = Cells(I, 6).Value
Worksheets("PRICING DATABASE").Activate
myHdr = Sheets("Quote Template").Range("O1")
Set aCell = Sheets("PRICING DATABASE").Range("A1:Z1").Find(What:=myHdr, _
LookIn:=xlValues, LookAt:=xlWhole, _
MatchCase:=False, SearchFormat:=False)
lastrowMS = Sheets("PRICING DATABASE").Cells(Rows.Count, 1).End(xlUp).Row
For p = 2 To lastrowMS
If Cells(p, 3) = partNumber And Cells(p, 8) <> specialPrice Then
Cells(p, 3) = partNumber
Cells(p, 8) = specialPrice
End If
Next p
Worksheets("QUOTE TEMPLATE").Activate
Next I
Application.ScreenUpdating = True