Vlookup Date

mezzy01

Board Regular
Joined
Nov 7, 2005
Messages
54
Hi board,

Can you tell me why this code can not look up dates. I've got a date in A1 and dates in A:B (Column A). It would be very much appreciated....thanxs

Sub Example_of_Vlookup()
Dim lookFor As Range
Dim rng As Range
Dim col As Integer
Dim found As Variant

Set lookFor = Sheets("Sheet1").Range("A1")
Set rng = Sheets("b").Columns("A:B")
col = 2

On Error Resume Next
found = Application.VLookup(lookFor.Value, rng, col, 0)
If IsError(found) Then
MsgBox lookFor & " not found"
Else: MsgBox "The look-up value of " & lookFor & " is " & found & " in column " & col
End If
On Error GoTo 0
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
What problems are you having?
 
Upvote 0
You are missing the word WorksheetFunction.

It should be Application.WorksheetFunction.Vlookup
 
Upvote 0
Kristy

Well spotted, didn't even see that. :oops:
 
Upvote 0
Thanxs for the fix.

Now that's working, how can I paste a range from Sheets("Sheet1")to the right of the date found in Sheets("b")

Would appreciate some help

thanxs
 
Upvote 0
Von Pookie said:
You are missing the word WorksheetFunction.

It should be Application.WorksheetFunction.Vlookup
Actually, that's not required. And I'm really surprised that it works with the WorksheetFunction and not without it, that's the first time I've seen that.
 
Upvote 0
I couldn't get it to work correctly until I added WorksheetFunction. *shrug*

I usually leave off Application and just use WorksheetFunction, myself :)
 
Upvote 0

Forum statistics

Threads
1,207,257
Messages
6,077,339
Members
446,278
Latest member
hoangquan2310

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top