Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Using VLookup formula in a macro

I am creating a visual basic macro to work with time data. In the data the
staff names are in the first column. I want a macro that can be started at
multiple locations in the worksheet. I want to pull data from a VLookup
table the macro has inserted on another part of the worksheet.

My macro is using relative reference with a multiply formula and works fine.
When I try to use a specific cell, say A3 as the search value for the
VLookup arguments, it works fine, but only grabs the absolute cell A3. So I
tried to use RC relative reference for the search value and It says compile
error. I tried every imaginable way to fill in the search value cell and I
can't get it to work.
A Line of macro follows:
ActiveCell.Offset(0, 16).Formula = "=VLOOKUP(RC[-16],V$3:W$20,2,FALSE)"
What form of reference might work?


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 419
Default Using VLookup formula in a macro

Relative Ref in VLookup for search value,

I don't have too much experience with stuff like this, but you might try the
"FormulaR1C1" property of the range object:

ActiveCell.Offset(0, 16).FormulaR1C1 = "=VLOOKUP(RC[-16],V$3:W$20,2,FALSE)"

instead of

ActiveCell.Offset(0, 16).Formula = "=VLOOKUP(RC[-16],V$3:W$20,2,FALSE)"

Another thing you could try is something like this:

ActiveCell.Offset(0, 16).Formula = "=VLOOKUP(" & cells(activecell.row,
activecell.column - 16).address & ",V$3:W$20,2,FALSE)"

Look up the "Address" property of the range object in help. It has some
arguments that can effect the style (relative, absolute, external) of the
address returned.

Something else I noticed, your reference to the lookup table has absolute
rows, but the columns are relative. If you ever have to copy/fill this
formula accross, your look up table will change. You might consider making
the lookup tables columns absolute as well if that is a concern.

HTH,

Conan







"Relative Ref in VLookup for search value" <Relative Ref in VLookup for
search wrote in message
...
I am creating a visual basic macro to work with time data. In the data the
staff names are in the first column. I want a macro that can be started
at
multiple locations in the worksheet. I want to pull data from a VLookup
table the macro has inserted on another part of the worksheet.

My macro is using relative reference with a multiply formula and works
fine.
When I try to use a specific cell, say A3 as the search value for the
VLookup arguments, it works fine, but only grabs the absolute cell A3. So
I
tried to use RC relative reference for the search value and It says
compile
error. I tried every imaginable way to fill in the search value cell and
I
can't get it to work.
A Line of macro follows:
ActiveCell.Offset(0, 16).Formula = "=VLOOKUP(RC[-16],V$3:W$20,2,FALSE)"
What form of reference might work?




  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Using VLookup formula in a macro



"Conan Kelly" wrote:

Relative Ref in VLookup for search value,

I don't have too much experience with stuff like this, but you might try the
"FormulaR1C1" property of the range object:

ActiveCell.Offset(0, 16).FormulaR1C1 = "=VLOOKUP(RC[-16],V$3:W$20,2,FALSE)"

instead of

ActiveCell.Offset(0, 16).Formula = "=VLOOKUP(RC[-16],V$3:W$20,2,FALSE)"

Another thing you could try is something like this:

ActiveCell.Offset(0, 16).Formula = "=VLOOKUP(" & cells(activecell.row,
activecell.column - 16).address & ",V$3:W$20,2,FALSE)"

Look up the "Address" property of the range object in help. It has some
arguments that can effect the style (relative, absolute, external) of the
address returned.

Something else I noticed, your reference to the lookup table has absolute
rows, but the columns are relative. If you ever have to copy/fill this
formula accross, your look up table will change. You might consider making
the lookup tables columns absolute as well if that is a concern.

HTH,

Conan







"Relative Ref in VLookup for search value" <Relative Ref in VLookup for
search wrote in message
...
I am creating a visual basic macro to work with time data. In the data the
staff names are in the first column. I want a macro that can be started
at
multiple locations in the worksheet. I want to pull data from a VLookup
table the macro has inserted on another part of the worksheet.

My macro is using relative reference with a multiply formula and works
fine.
When I try to use a specific cell, say A3 as the search value for the
VLookup arguments, it works fine, but only grabs the absolute cell A3. So
I
tried to use RC relative reference for the search value and It says
compile
error. I tried every imaginable way to fill in the search value cell and
I
can't get it to work.
A Line of macro follows:
ActiveCell.Offset(0, 16).Formula = "=VLOOKUP(RC[-16],V$3:W$20,2,FALSE)"
What form of reference might work?





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 Macro? ctwobits Excel Discussion (Misc queries) 0 December 6th 07 09:42 PM
changing a vlookup formula using a macro Arain Excel Discussion (Misc queries) 6 October 23rd 07 05:12 PM
vlookup macro MikeD1224 New Users to Excel 1 June 16th 07 04:37 AM
VLOOKUP in a macro?? chip_pyp Excel Discussion (Misc queries) 1 March 27th 06 09:40 PM
Macro puts #REF in VLOOKUP formula DJH224 Excel Worksheet Functions 1 January 27th 06 05:37 PM


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