Have two columns of value on different worksheet, for each value of column A (Plan1), check with column B (Plan5), if equal, write on a cell in Plan1

Viewed 30

I am having trouble to check different values on different worksheets. I think this problem is very simple, yet, I am spending much time because it is not working :P

Code:

Dim a As Integer
a = 6
Dim p As Integer
p = 3

While a <> 10
    While p <> 5
        test = Plan1.Range("B" & a).Value
        test2 = Plan5.Range("F" & p).Value
        If test = test2 Then
            Plan1.Range("I" & a).Select
            ActiveCell.FormulaR1C1 = "Value found"
        Else
            Plan1.Range("I" & a).Select
            ActiveCell.FormulaR1C1 = "Value not found"
        End If
        p = p + 1
    Wend
    a = a + 1
Wend
End Sub

Code with Match Function as suggested by BigBen, still giving me 1004 Error.

Sub printer()

Plan1.Range("I6").Value = WorksheetFunction.Match(Plan1.Range("B6").Value, Plan5.Range("B2:B400"))

End Sub
0 Answers
Related