I am working as a Data Analyst for a software startup where I am required to write macros to analyse and sort data more efficiently. I am currently working on a macro that takes a value one workbook ("Job MMRF") and searches for it in another ("U100 Material Information"). My code is as follows:
Sub MMRFValidation()
Dim c As Range
Dim leadtime As Double
Dim price As Double
Application.ScreenUpdating = False
With Workbooks("Job MMRF.csv")
For Each c In Range("C:C")
If c.Value = "" Then
c.Offset(, -2).Font.Color = vbRed
c.Offset(, 9).Value = "Need to contact vendor"
c.Offset(, 10).Value = "Need to contact vendor"
Else
Dim a As Range
With Workbooks("U100 Material Information.xlsx")
For Each a In Range("A:A")
If a.Value = c.Value Then
price = a.Offset(, 15).Value
leadtime = a.Offset(, 13).Value
End If
Next a
End With
If price = 0.01 And leadtime = 21 Then
c.Offset(, -2).Font.ColorIndex = 7
c.Offset(, 9).Value = leadtime
c.Offset(, 10).Value = price
Else
c.Offset(, -2).Font.Color = vbGreen
c.Offset(, 9).Value = leadtime
c.Offset(, 10).Value = price
End If
End If
Next c
End With
Application.ScreenUpdating = True
End Sub
c is the value from the first workbook. I am trying to find c in the second workbook. If it is found, I want to copy the values from the 13th and 15th column in the U100 wb (associated with the row where c was found) and paste these values into the 9th and 10th row in JobMMRF (associated with the row where c initially was). The part of the code that changes font color works, but the price/lead time part does not. Pls help, thanks.
edit: I have updated the code. Now it pulls price and leadtime values, but for some reason they are always 0.