Update values based criteria and header cell value

RasGhul

Well-known Member
Joined
Jul 15, 2016
Messages
797
Office Version
  1. 365
Platform
  1. 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
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,223,911
Messages
6,175,334
Members
452,636
Latest member
laura12345

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