Using Built in Functions in VB Code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I apologize if this is some trivial question that has an easy answer, but I
have been through help and 2 different Excel VB books and cannot get this to
work.

Problem: In a VB Function, I would like to do the following:

Pos = VLookup(InValue, NamedTable, 2, FALSE)

The debugger won't let me use VLookup. I also tried Average, etc., and the
debugger pops on whatever built-in function I use.

Is there a flag I can set, or a technique I need to use to make this work?

I really know excel, but am a novice at VB. I can get around it nesting
vlookups in the spreadsheet, but it is really ugly. Being able to do this
would enable me to clean up my code a bunch. I would welcome feedback.

Regards,

Jim
 
Hi Jim

Use it like this

Application.WorksheetFunctionVLookup(.............................)
 
Hi Jim, Ron,

A dot after WorksheetFunction

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

| Hi Jim
|
| Use it like this
|
| Application.WorksheetFunctionVLookup(.............................)
|
|
| --
| Regards Ron de Bruin
| http://www.rondebruin.nl
|
|
|
| >I apologize if this is some trivial question that has an easy answer, but I
| > have been through help and 2 different Excel VB books and cannot get this to
| > work.
| >
| > Problem: In a VB Function, I would like to do the following:
| >
| > Pos = VLookup(InValue, NamedTable, 2, FALSE)
| >
| > The debugger won't let me use VLookup. I also tried Average, etc., and the
| > debugger pops on whatever built-in function I use.
| >
| > Is there a flag I can set, or a technique I need to use to make this work?
| >
| > I really know excel, but am a novice at VB. I can get around it nesting
| > vlookups in the spreadsheet, but it is really ugly. Being able to do this
| > would enable me to clean up my code a bunch. I would welcome feedback.
| >
| > Regards,
| >
| > Jim
| >
| > --------------
| > Jim Conrady
| > (e-mail address removed)
|
|
 
I like to do it this way:

Dim Pos as Variant 'could return an error
dim inValue as Variant 'string, number, what???
dim namedtable as Range

with worksheets("somesheet")
set namedtable = .range("sometablerangehere")
end with

pos = application.vlookup(invalue, namedtable, 2, false)

if iserror(pos) then
'not found
else
'found, rest of code goes here
end if

This assumes that invalue and namedtable are variables in your code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top