Lookup function in VBA

F

Fred Smith

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? > )
 
D

Dave Peterson

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).)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top