Error 2042 problem with vlookup

D

Dominique Feteau

I'm having a problem trying to use a simple vlookup request and match it to
another variable.

Two tables on two sheets. The problem I'm having is that when the vlookup
request to the array comes back as an error when it shouldn't. I've looked
at this code 100 times and I can't find an error. Any help??

Sheet1
501 Description A
502 Description B
503 Description C
504 Description D

Sheet2
500 5/16/2011 TEST0
500 5/16/2011 TEST1
500 5/16/2011 TEST2
501 5/16/2011 TEST3
503 5/16/2011 TEST4
503 5/16/2011 TEST5
504 5/16/2011 TEST6

Here is my code:

Sub KeepTrying()

Sheets("Sheet2").Activate
'Get Count
Range("A1").Select
i = 0
Do Until ActiveCell.Value = ""
ActiveCell.Offset(1, 0).Select
i = i + 1
Loop

'Create Array using count
Dim tableA() As Variant
ReDim tableA(1 To i, 1 To 3)
Range("A1").Select
x = 1
Do Until x = i + 1
tableA(x, 1) = ActiveCell.Offset(0, 0).Value
tableA(x, 2) = ActiveCell.Offset(0, 1).Value
tableA(x, 2) = ActiveCell.Offset(0, 2).Value
ActiveCell.Offset(1, 0).Select
x = x + 1
Loop

'Check
Sheets("Sheet1").Activate
Range("A1").Select
Do Until ActiveCell.Value = ""
For d = 1 To i
code = ActiveCell.Value
codeCheck = Application.VLookup(d, tableA, 1, False) - PROBLEM!!!
If code = codeCheck Then
ActiveCell.Offset(0, 3).FormulaR1C1 = "Y"
ActiveCell.Offset(1, 0).Select
End If
Next
Loop

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top