Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default VLOOKUP not working in VBA

I am trying to perform at lookup in a defined range name=DemoEndDate.
Res comes back as blank. Is this the correct format?? Also, does anyone
know if this is the correct date format?

YY = Year(Worksheets("RFJ").Range("N8"))
MM = Month(Worksheets("RFJ").Range("N8"))
SDate = DateSerial(YY, MM, 1)

Dim YY As String
Dim MM As String
Dim SDate As Date

Res = Application.WorksheetFunction.VLookup(SDate, Range("DemoOEndDate"), 2,
False)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default VLOOKUP not working in VBA

If res is coming back as blank ("", right?), then I think your =vlookup() is
working fine. But the first match for that date has a cell that looks empty.

======
You're not sharing all your code--are you masking any problems with an "on error
resume next" line?

ps.

I'd use this version--with two important changes.

I'd use application.vlookup() instead of application.worksheetfunction.vlookup()
because of the way no matches are handled.

And I'd use clng(sdate). Dates can be funny things to find matches with.

dim Res as variant
....
Res = Application.VLookup(clng(SDate), Range("DemoOEndDate"), 2, False)

if iserror(res) then
'not found
else
msgbox res
end if


DogLover wrote:

I am trying to perform at lookup in a defined range name=DemoEndDate.
Res comes back as blank. Is this the correct format?? Also, does anyone
know if this is the correct date format?

YY = Year(Worksheets("RFJ").Range("N8"))
MM = Month(Worksheets("RFJ").Range("N8"))
SDate = DateSerial(YY, MM, 1)

Dim YY As String
Dim MM As String
Dim SDate As Date

Res = Application.WorksheetFunction.VLookup(SDate, Range("DemoOEndDate"), 2,
False)


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 915
Default VLOOKUP not working in VBA

DogLover wrote:
I am trying to perform at lookup in a defined range name=DemoEndDate.
Res comes back as blank. Is this the correct format?? Also, does anyone
know if this is the correct date format?

YY = Year(Worksheets("RFJ").Range("N8"))
MM = Month(Worksheets("RFJ").Range("N8"))
SDate = DateSerial(YY, MM, 1)

Dim YY As String
Dim MM As String
Dim SDate As Date

Res = Application.WorksheetFunction.VLookup(SDate, Range("DemoOEndDate"), 2,
False)


You could try this modification:

Res = Application.WorksheetFunction.VLookup(CLng(SDate),
Range("DemoOEndDate"), 2, False)

See also my comments in this recent thread:

http://preview.tinyurl.com/y8rlfry
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default VLOOKUP not working in VBA


These changes worked! Thank you both!!

"DogLover" wrote:

I am trying to perform at lookup in a defined range name=DemoEndDate.
Res comes back as blank. Is this the correct format?? Also, does anyone
know if this is the correct date format?

YY = Year(Worksheets("RFJ").Range("N8"))
MM = Month(Worksheets("RFJ").Range("N8"))
SDate = DateSerial(YY, MM, 1)

Dim YY As String
Dim MM As String
Dim SDate As Date

Res = Application.WorksheetFunction.VLookup(SDate, Range("DemoOEndDate"), 2,
False)

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
If (Vlookup 0) working, but what if Vlookup cell does not exist Steve Excel Worksheet Functions 18 November 18th 09 07:33 PM
vlookup not working JonOxford Excel Programming 2 July 29th 09 08:15 PM
VLookup not working Scott Excel Worksheet Functions 2 January 29th 08 03:13 PM
VLOOKUP not working Small One Excel Discussion (Misc queries) 4 May 31st 07 05:42 PM
Vlookup not working for me. Tbram Excel Worksheet Functions 1 May 8th 07 05:14 PM


All times are GMT +1. The time now is 11:20 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"