Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Named Range in VBA

Hi,

I'm trying to use Vlookup in a UDF and would like to used a named range I
already have specified as the lookup range. Excel doesn't like the 'raw'
reference.

e.g.

Function Include(Client As Variant, Task As Variant)

If WorksheetFunction.VLookup(Client, ClientTable, 2, False) = "Yes" Then
Include = "Yes"
..... more to come...

End Function

Any suggestiosn please?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Named Range in VBA

You still need to use the Range object, with the name, like

Range("range_name")

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Jon C" wrote in message
...
Hi,

I'm trying to use Vlookup in a UDF and would like to used a named range I
already have specified as the lookup range. Excel doesn't like the 'raw'
reference.

e.g.

Function Include(Client As Variant, Task As Variant)

If WorksheetFunction.VLookup(Client, ClientTable, 2, False) = "Yes" Then
Include = "Yes"
.... more to come...

End Function

Any suggestiosn please?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Named Range in VBA

In addition to Bob's suggestion, unless you have a compelling reason
not to, I would strongly urge you to include the lookup table as an
argument to the UDF.

For example, if your table is in columns A:B starting with row 1 (row 1
being a header), define the name
ClientTable =OFFSET(Sheet1!$A$2,0,0,COUNTA(Sheet1!$A:$A)-1,2)

Now, use the UDF as =include(D2,ClientTable,1)

The revised UDF looks like:
Option Explicit

Function Include(Client As Variant, ClientTable As Range, _
Task As Variant)
If Application.WorksheetFunction.VLookup( _
Client, ClientTable, 2, False) = "Yes" Then
Include = "Yes"
'.... more to come...
Else
Include = "No"
End If
End Function


--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Hi,

I'm trying to use Vlookup in a UDF and would like to used a named range I
already have specified as the lookup range. Excel doesn't like the 'raw'
reference.

e.g.

Function Include(Client As Variant, Task As Variant)

If WorksheetFunction.VLookup(Client, ClientTable, 2, False) = "Yes" Then
Include = "Yes"
.... more to come...

End Function

Any suggestiosn please?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Named Range in VBA

Terrific. Thanks Bob and Tushar.

Jon


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
Referencing a named range based upon Range name entry in cell Barb Reinhardt Excel Worksheet Functions 14 June 20th 07 07:19 PM
automatic range - named range give me circular reference... George Thorogood Excel Discussion (Misc queries) 0 February 22nd 07 07:53 PM
Array as a "named range" - formula ok in cells, but error as "named range" tskogstrom Excel Discussion (Misc queries) 11 December 28th 06 04:44 PM
inserting a named range into new cells based on a named cell Peter S. Excel Discussion (Misc queries) 1 June 4th 06 03:53 AM
Can I use named range in data range box when creating pie chart? BJackson Charts and Charting in Excel 2 August 17th 05 05:37 PM


All times are GMT +1. The time now is 12:16 AM.

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"