Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 623
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 623
Default 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
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
Combining Lookup function and Sum function Cameron Excel Worksheet Functions 2 July 13th 09 02:19 AM
LOOKUP FUNCTION? (LOOKUP VALUE BEING A TIME RENERATED FROM A FORMU JCC Excel Discussion (Misc queries) 5 June 26th 09 09:15 PM
Excel Data Validation/Lookup function does function correcty Kirkey Excel Worksheet Functions 2 May 25th 09 09:22 PM
how to combine an IF Function with a lookup function to determine [email protected] Excel Worksheet Functions 1 December 5th 06 06:09 AM
Pivot table doing a lookup without using the lookup function? NGASGELI Excel Discussion (Misc queries) 0 August 2nd 05 05:08 AM


All times are GMT +1. The time now is 07:16 PM.

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"