Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default setting ranges and vlookup in custom functions

Hi,

below is a piece of code of a custom function I worked on:

Function Futures_unr(maturity As Date) As Double
Dim lookuprng As Range, adj_maturity As Variant, a As Variant

If Weekday(maturity, vbMonday) = 5 Then
adj_maturity = (Day(maturity) + 3) & "/" & Month(maturity) & "/" &
Year(maturity)
Else
adj_maturity = (Day(maturity) + 1) & "/" & Month(maturity) & "/" &
Year(maturity)
End If

Set lookuprng = ThisWorkbook.Worksheets("Sheet1").Range("E6:J83")
a = Application.WorksheetFunction.VLookup(adj_maturity , lookuprng, 2, False)
Futures_unr = a
End Function

so the input is a date and output should be a numerical value. I get an
error while, I think, trying to set up a range for vlookup. Does any have any
idea what is causing an error? (vlookup in excel function works fine) Thank
you in advance.

regards,
S
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default setting ranges and vlookup in custom functions

Function Futures_unr(maturity As Date) As Double
Dim lookuprng As Range, adj_maturity As Variant, a As Variant

If Weekday(maturity, vbMonday) = 5 Then
adj_maturity = maturity + 3
Else
adj_maturity = maturity + 1
End If

Set lookuprng = ThisWorkbook.Worksheets("Sheet1").Range("E6:J83")
a = Application.VLookup(CLng(adj_maturity), lookuprng, 2, False)
Futures_unr = a
End Function

--
__________________________________
HTH

Bob

"SPavlyuk" wrote in message
...
Hi,

below is a piece of code of a custom function I worked on:

Function Futures_unr(maturity As Date) As Double
Dim lookuprng As Range, adj_maturity As Variant, a As Variant

If Weekday(maturity, vbMonday) = 5 Then
adj_maturity = (Day(maturity) + 3) & "/" & Month(maturity) & "/" &
Year(maturity)
Else
adj_maturity = (Day(maturity) + 1) & "/" & Month(maturity) & "/" &
Year(maturity)
End If

Set lookuprng = ThisWorkbook.Worksheets("Sheet1").Range("E6:J83")
a = Application.WorksheetFunction.VLookup(adj_maturity , lookuprng, 2,
False)
Futures_unr = a
End Function

so the input is a date and output should be a numerical value. I get an
error while, I think, trying to set up a range for vlookup. Does any have
any
idea what is causing an error? (vlookup in excel function works fine)
Thank
you in advance.

regards,
S



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default setting ranges and vlookup in custom functions

Bob, thanks!

so I understand I did a mistake in handling the date value... it works well
now. thanks again.

regards,
Sergiy

"Bob Phillips" wrote:

Function Futures_unr(maturity As Date) As Double
Dim lookuprng As Range, adj_maturity As Variant, a As Variant

If Weekday(maturity, vbMonday) = 5 Then
adj_maturity = maturity + 3
Else
adj_maturity = maturity + 1
End If

Set lookuprng = ThisWorkbook.Worksheets("Sheet1").Range("E6:J83")
a = Application.VLookup(CLng(adj_maturity), lookuprng, 2, False)
Futures_unr = a
End Function

--
__________________________________
HTH

Bob

"SPavlyuk" wrote in message
...
Hi,

below is a piece of code of a custom function I worked on:

Function Futures_unr(maturity As Date) As Double
Dim lookuprng As Range, adj_maturity As Variant, a As Variant

If Weekday(maturity, vbMonday) = 5 Then
adj_maturity = (Day(maturity) + 3) & "/" & Month(maturity) & "/" &
Year(maturity)
Else
adj_maturity = (Day(maturity) + 1) & "/" & Month(maturity) & "/" &
Year(maturity)
End If

Set lookuprng = ThisWorkbook.Worksheets("Sheet1").Range("E6:J83")
a = Application.WorksheetFunction.VLookup(adj_maturity , lookuprng, 2,
False)
Futures_unr = a
End Function

so the input is a date and output should be a numerical value. I get an
error while, I think, trying to set up a range for vlookup. Does any have
any
idea what is causing an error? (vlookup in excel function works fine)
Thank
you in advance.

regards,
S




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default setting ranges and vlookup in custom functions

Yeah, the thing to remember is that however it looks, a date is just a
number under the covers (the number of days since Jan 01 1900), so just work
with numbers.

--
__________________________________
HTH

Bob

"SPavlyuk" wrote in message
...
Bob, thanks!

so I understand I did a mistake in handling the date value... it works
well
now. thanks again.

regards,
Sergiy

"Bob Phillips" wrote:

Function Futures_unr(maturity As Date) As Double
Dim lookuprng As Range, adj_maturity As Variant, a As Variant

If Weekday(maturity, vbMonday) = 5 Then
adj_maturity = maturity + 3
Else
adj_maturity = maturity + 1
End If

Set lookuprng = ThisWorkbook.Worksheets("Sheet1").Range("E6:J83")
a = Application.VLookup(CLng(adj_maturity), lookuprng, 2, False)
Futures_unr = a
End Function

--
__________________________________
HTH

Bob

"SPavlyuk" wrote in message
...
Hi,

below is a piece of code of a custom function I worked on:

Function Futures_unr(maturity As Date) As Double
Dim lookuprng As Range, adj_maturity As Variant, a As Variant

If Weekday(maturity, vbMonday) = 5 Then
adj_maturity = (Day(maturity) + 3) & "/" & Month(maturity) & "/" &
Year(maturity)
Else
adj_maturity = (Day(maturity) + 1) & "/" & Month(maturity) & "/" &
Year(maturity)
End If

Set lookuprng = ThisWorkbook.Worksheets("Sheet1").Range("E6:J83")
a = Application.WorksheetFunction.VLookup(adj_maturity , lookuprng, 2,
False)
Futures_unr = a
End Function

so the input is a date and output should be a numerical value. I get an
error while, I think, trying to set up a range for vlookup. Does any
have
any
idea what is causing an error? (vlookup in excel function works fine)
Thank
you in advance.

regards,
S






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
help with setting up dynamic name ranges Jeff Excel Worksheet Functions 5 September 22nd 06 02:07 PM
Using custom functions within custom validation Neil Excel Discussion (Misc queries) 4 December 14th 05 10:40 PM
Ranges in Custom Functions JR Excel Programming 1 April 18th 05 03:43 PM
How to access ranges in closed workbooks in custom functions Deepak Agarwal Excel Programming 3 July 9th 04 01:59 PM
Setting ranges Scottie[_2_] Excel Programming 3 February 26th 04 06:22 PM


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