Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Lookup function in VBA
I want to call Lookup from a macro. In Excel, the function is:
=lookup(k12,{2,4,6,8;"A","V","X","Z"}) How do I do this in VBA, as in: cell.offset(0,16) = application.lookup(cell.offset(0,12), < what goes here? ) -- Regards, Fred |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Lookup function in VBA
I'd use something like:
Option Explicit Sub testme() Dim Arr1 As Variant Dim Arr2 As Variant Dim res As Variant Arr1 = Array(2, 4, 6, 8) Arr2 = Array("a", "v", "x", "z") res = Application.Lookup(4, Arr1, Arr2) If IsError(res) Then MsgBox "error" Else MsgBox res End If End Sub (I figured you could add the real stuff (where it goes and what should be matched).) Fred Smith wrote: I want to call Lookup from a macro. In Excel, the function is: =lookup(k12,{2,4,6,8;"A","V","X","Z"}) How do I do this in VBA, as in: cell.offset(0,16) = application.lookup(cell.offset(0,12), < what goes here? ) -- Regards, Fred -- Dave Peterson |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Lookup function in VBA
Thanks, Dave. Just what I needed.
-- Regards, Fred "Dave Peterson" wrote in message ... I'd use something like: Option Explicit Sub testme() Dim Arr1 As Variant Dim Arr2 As Variant Dim res As Variant Arr1 = Array(2, 4, 6, 8) Arr2 = Array("a", "v", "x", "z") res = Application.Lookup(4, Arr1, Arr2) If IsError(res) Then MsgBox "error" Else MsgBox res End If End Sub (I figured you could add the real stuff (where it goes and what should be matched).) Fred Smith wrote: I want to call Lookup from a macro. In Excel, the function is: =lookup(k12,{2,4,6,8;"A","V","X","Z"}) How do I do this in VBA, as in: cell.offset(0,16) = application.lookup(cell.offset(0,12), < what goes here? ) -- Regards, Fred -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Combining Lookup function and Sum function | Excel Worksheet Functions | |||
LOOKUP FUNCTION? (LOOKUP VALUE BEING A TIME RENERATED FROM A FORMU | Excel Discussion (Misc queries) | |||
Excel Data Validation/Lookup function does function correcty | Excel Worksheet Functions | |||
how to combine an IF Function with a lookup function to determine | Excel Worksheet Functions | |||
Pivot table doing a lookup without using the lookup function? | Excel Discussion (Misc queries) |