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

Hi,
I am not too hot on translating Excel function on VBA.
I am trying to use Vlookup and Hlookup to return a value
for each Cell in a selection. How can I declare the
functions for them to work in the following way?

This is part of the code, where Price and CountryToSearch
are defined as Range:

Dim Cell As Range
For Each Cell In Selection
Cell.Offset(0, 10).Value = VLookup(Cell, Price, HLookup
(CountryToSearch, Price, 2, False), False)
Next Cell

Can somebody help? Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using vlookup in VBA


Dim Cell As Range
For Each Cell In Selection
Cell.Offset(0, 10).Value = Application.VLookup(Cell, _
Range("Price"), Application.HLookup _
(Range("CountryToSearch"), Range("Price"), 2, False), False)
Next Cell

Assume your formula arguments and name definitions are appropriate.

--
Regards,
Tom Ogilvy


"Caroline" wrote in message
...
Hi,
I am not too hot on translating Excel function on VBA.
I am trying to use Vlookup and Hlookup to return a value
for each Cell in a selection. How can I declare the
functions for them to work in the following way?

This is part of the code, where Price and CountryToSearch
are defined as Range:

Dim Cell As Range
For Each Cell In Selection
Cell.Offset(0, 10).Value = VLookup(Cell, Price, HLookup
(CountryToSearch, Price, 2, False), False)
Next Cell

Can somebody help? Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Using vlookup in VBA

Thanks Tom. It works. Did not realise it was as simple as
typing Application in front of it.
-----Original Message-----

Dim Cell As Range
For Each Cell In Selection
Cell.Offset(0, 10).Value = Application.VLookup(Cell, _
Range("Price"), Application.HLookup _
(Range("CountryToSearch"), Range("Price"), 2, False),

False)
Next Cell

Assume your formula arguments and name definitions are

appropriate.

--
Regards,
Tom Ogilvy


"Caroline" wrote

in message
...
Hi,
I am not too hot on translating Excel function on VBA.
I am trying to use Vlookup and Hlookup to return a

value
for each Cell in a selection. How can I declare the
functions for them to work in the following way?

This is part of the code, where Price and

CountryToSearch
are defined as Range:

Dim Cell As Range
For Each Cell In Selection
Cell.Offset(0, 10).Value = VLookup(Cell, Price, HLookup
(CountryToSearch, Price, 2, False), False)
Next Cell

Can somebody help? Thanks



.

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
If (Vlookup 0) working, but what if Vlookup cell does not exist Steve Excel Worksheet Functions 18 November 18th 09 07:33 PM
VLookUp - Does the VLookUp return the exact information? Cpviv Excel Worksheet Functions 2 October 28th 08 09:57 AM
Vlookup in vlookup - taking the result as array name SupperDuck Excel Worksheet Functions 2 June 2nd 07 11:05 AM
Vlookup -=VLOOKUP(F9,LookUp1!$A$2:$B$1504,2,FALSE) MikeR-Oz New Users to Excel 1 March 22nd 06 09:01 AM
Vlookup info being used without vlookup table attached? Excel Worksheet Functions 0 January 25th 05 10:43 AM


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