Update values based criteria and header cell value

RasGhul

Well-known Member
Joined
Jul 15, 2016
Messages
609
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
 

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Watch MrExcel Video

Forum statistics

Threads
1,109,335
Messages
5,528,096
Members
409,802
Latest member
joeino

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top