ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using vlookup in VBA (https://www.excelbanter.com/excel-programming/285021-using-vlookup-vba.html)

Caroline[_2_]

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

Tom Ogilvy

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




No Name

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



.



All times are GMT +1. The time now is 12:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com