![]() |
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 |
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 |
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 |
All times are GMT +1. The time now is 07:40 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com