问题
We are trying to make a macro that takes a value from column (c) and searches for a value on a separate workbook then pulls two pieces of information from one row and two separate columns. The rest of the code is just turning a word red or green depending on if there is information in the column.
The VLookup function that we are using turns red when we paste it into the excel vba, what are we doing wrong and is there a simple way to fix this. The code is below,
Sub MMRFValidation()
Dim c As Range
Dim finder As Range
Application.ScreenUpdating = False
For Each c In Range("C:C")
If c.Value = "" Then
c.Offset(, -2).Font.Color = vbRed
c.Offset(, 11).Value = "Need to contact vendor"
c.Offset(, 12).Value = "Need to contact vendor"
Else
Set finder = Range("C:C").Find(what:=Workbook("U100 Material Information.xlsx").Worksheet("Sheet1").Range("A:A"), LookIn:=xlValues, LookAt:=xlWhole)
leadtime = finder.Offset(, 13).Value
price = finder.Offset(, 15).Value
If price = "0.01" And leadtime = "21" Then
c.Offset(, -2).Font.ColorIndex = 7
c.Offset(, 11).Value = finder.Offset(, 13).Value
c.Offset(, 11).Value = finder.Offset(, 15).Value
Else
c.Offset(, -2).Font.Color = vbGreen
c.Offset(, 11).Value = finder.Offset(, 13).Value
c.Offset(, 11).Value = finder.Offset(, 15).Value
End If
End If
Next c
Application.ScreenUpdating = True
End Sub
Thanks
来源:https://stackoverflow.com/questions/60439572/using-vlookup-in-excel-vba-for-multiple-worksheets