LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
wal wal is offline
external usenet poster
 
Posts: 19
Default Unable to get the VLookup property - worksheet.function error

I'm trying to create, in VBA, a function using worksheet functions to
avoid an overly complex formula directly in worksheet cells. But I
keep getting the error "Unable to get the VLookup property of the
WorksheetFunction class"

As a simple example, here is the function if placed in the worksheet
itself (in C10):

=IF(ISNA(VLOOKUP(A10+B10,HolidayList,
1,FALSE)=FALSE),A10+B10,A10+B10+1)

The range "HolidayList" lists dates of holidays. Cell A10 is the
start date; cell B10 is the number of days from the start date; cell
C10 is the deadline I want to find. Basically: If the deadline falls
on a date in "HolidayList" add an extra day.

I converted the formula to VBA, as follows:

***
Function DeadlineDate(StartDate, NumberOfDays%)

Application.Volatile

If WorksheetFunction.IsNA(WorksheetFunction.VLookup(C Lng(StartDate) +
_ NumberOfDays, Range("HolidayList"), 1, False)) = True Then
DeadlineDate = CLng(StartDate) + NumberOfDays
Else: DeadlineDate = CLng(StartDate) + NumberOfDays + 1
End If

End Function
***

In C10, the formula is now simply: =deadlinedate(A10,B10)

The problem: Whatever values are in A10 and B10, the Watch I created
for WorksheetFunction.VLookup(StartDate + NumberOfDays,
Range("HolidayList"), 2, False) shows the error value "Unable to get
the VLookup property of the WorksheetFunction class".

Interestingly, if A10 and B10 add up to a date that is found in
HolidayList, the correct deadline date appears in C10, even though the
"Unable to get . . ." error appears in the Watch.

However, if A10 and B10 add up to a date not found on the list, the
value in C10 is #VALUE! (and the "Unable to get . . ." error appears
in the Watch).

Any ideas how to correct the code to make VLookup work in all cases?
Thanks.
 
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
Run-Time error '1004: Unable to get the PivotTables property of the worksheet class magarnagle Excel Programming 4 May 19th 06 11:20 AM
Run time error 1004 - unable to get the chartObjects property of the worksheet class hedgehog1 Excel Programming 1 April 10th 06 08:10 PM
Runtime error 1004 - unable to set Visible property of Worksheet c SueJB Excel Programming 2 October 4th 05 02:27 PM
Error: Unable to get the OLEObjects property of the worksheet class Grant Excel Programming 2 August 6th 04 02:20 PM
Run-time error '1004' - Unable to set the Visible property of the Worksheet class Shalin Chopra Excel Programming 3 November 25th 03 08:38 PM


All times are GMT +1. The time now is 09:13 PM.

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

About Us

"It's about Microsoft Excel"