I am hoping someone can help. I am comparing prices of products between a master sheet and a local sheet. I need to flag when the prices don't match. The master sheet contains all possible products but the local sheets do not, so first I need to match the products based on their product code and then based on that result, match the prices. VLookup didn't quite get me where I wanted to go, although I am open to suggestion, so I have tried my hand at the following code:
Sub match_price()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Set ws1 = ActiveSheet
Set ws2 = Worksheets("master")
For Each i In ws1.Range("A2:A100")
For Each C In ws2.Range("A2:A75")
If i.Cells.Value = C.Cells.Value Then
ws1.Range("C2:C10").Select
End If
Next C
Next i
For Each i In ws1.Range("C2:C100")
For Each C In ws2.Range("C2:C75")
If i.Cells.Value < C.Cells.Value Then
i.Cells.Interior.ColorIndex = 3
End If
Next C
Next i
End Sub
However, my solution is not recognizing the differences, I suspect this is because it is not fully picking up that the differences should only be based on matched products. Any help is appreciated, thanks in advance.
EDIT
SAMPLE DATA
Master Sheet
ID Descrip Invoice
14562738 A 119
25364058 B 245
26584024 C 375
67489542 D 19
Local Sheet
ID Descrip Invoice
14562738 A 115
25364058 B 240
67489542 D 19
Edit 2: My resolution:
In case anyone is interested, I recorded a macro with my Vlookup code and added user2140261 conditional formatting for the flagging. I only wanted to highlight the text so I removed the coloring of the cell itself. I should mention that I need to use VBA as there are other types of calculations that I need to do across many cells and sheets, but user2140261 highlighting solution helped me take Vlookup to where I need to be. Thank you for your help!
Sub Macro()
'
'I always select D2 as the default active cell.
Range("D2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-3],master,3,FALSE)"
Selection.AutoFill Destination:=Range("D2:D10"), Type:=xlFillDefault
Range("C2:C10").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
Formula1:="=D2"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
End Sub