Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
CCL CCL is offline
external usenet poster
 
Posts: 1
Default Vlookup Cannot Find a Particular Date in a Range?

When I use a Vlookup function in VBA to search the record entry dates from a
range, it cannot find the record and just returns the run-time error. I am
sure that the particular dates exist in the range since I have used Countif
in VBA and Vlookup in worksheet to test if it exists. Could anybody tell me
why?

Price=Application.WorksheetFunction.Vlookup(EntyDa te,Sheets("Price").Columns("A:B"),2,0)

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Vlookup Cannot Find a Particular Date in a Range?

Use Range instead of Columns

Price=Application.WorksheetFunction.Vlookup(EntyDa te,Sheets("Price").Range("A:B"),2,0)

But if a date is not there, it will look through the entire column. So it is better to limit the range to the rows that actually
contain data.

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"CCL" wrote in message ...
| When I use a Vlookup function in VBA to search the record entry dates from a
| range, it cannot find the record and just returns the run-time error. I am
| sure that the particular dates exist in the range since I have used Countif
| in VBA and Vlookup in worksheet to test if it exists. Could anybody tell me
| why?
|
| Price=Application.WorksheetFunction.Vlookup(EntyDa te,Sheets("Price").Columns("A:B"),2,0)
|
| Thanks
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Vlookup Cannot Find a Particular Date in a Range?

Dim Entrydate as Double worked for me

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"CCL" wrote in message ...
| Hi Niek,
|
| Thank you for you advice. I have tried it in Excel 2000 and Excel xp, but
| failed. I still got the run-time error 1004. The following is my sample
| program for your information. Do you have any idea?
|
| Sub TestExtreivePrice()
|
| Dim EntryDate As Date
| Dim Price As Double
|
| EntryDate = Sheets("Price").Range("G1").Value ' G1=02 Dec 2006
|
| Price = Application.WorksheetFunction.VLookup(EntryDate,
| Sheets("Price").Range("A2:B12"), 2, 0)
|
| MsgBox "Price on " & EntryDate & " = " & Price
|
| End Sub
|
| Thanks a lot
|
| "CCL" ??:
|
| When I use a Vlookup function in VBA to search the record entry dates from a
| range, it cannot find the record and just returns the run-time error. I am
| sure that the particular dates exist in the range since I have used Countif
| in VBA and Vlookup in worksheet to test if it exists. Could anybody tell me
| why?
|
| Price=Application.WorksheetFunction.Vlookup(EntyDa te,Sheets("Price").Columns("A:B"),2,0)
|
| Thanks
|


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
vlookup(date, range,3) David Excel Worksheet Functions 3 March 16th 10 09:06 PM
using vlookup to find data outside a specified range Art Excel Worksheet Functions 1 March 9th 10 11:09 PM
Find Last cell in Range when range is date format default105 Excel Discussion (Misc queries) 5 July 7th 09 03:11 PM
How to find date in a range? hideki[_21_] Excel Programming 1 November 26th 05 04:16 AM
Find date and copy range based on that date avzundert Excel Programming 2 November 25th 04 10:31 AM


All times are GMT +1. The time now is 09:22 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"