ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Lookup Function in Macro (VBA) (https://www.excelbanter.com/excel-programming/428804-lookup-function-macro-vba.html)

smartguy0753

Lookup Function in Macro (VBA)
 
Hi,

I am trying to 'Record a Macro' in the new Excel 2007 that includes the
LOOKUP Function. However, when I finish recording and try to run it, I get
errors. From what I understand, it is because it has a "{" in the formula.
However, that's just how it is entered. (basically, i want it to look in the
specified cell and place the corresponding value in the selected cell)

Does anyone have a solution to this so that the Macro will run?

Thanks.

Here is the idea of the LOOKUP...
=LOOKUP(I2,{"1","3","5"},{"help","this","the"})

Bernie Deitrick

Lookup Function in Macro (VBA)
 
All right smart guy,

If you are trying to add the formula to a cell:

ActiveCell.Formula = _
"=LOOKUP(I2,{""1"",""3"",""5""},{""help"",""this"" ,""the""})"

IF you are trying to get the value of that formula:

Dim myVar As String
myVar = Application.WorksheetFunction.Lookup(Range("I2").V alue, _
Array("1", "3", "5"), Array("help", "this", "the"))

Note that the formula is looking for the string value 1 and not the number 1
in cell I2.

HTH,
Bernie
MS Excel MVP



"smartguy0753" wrote in message
...
Hi,

I am trying to 'Record a Macro' in the new Excel 2007 that includes the
LOOKUP Function. However, when I finish recording and try to run it, I get
errors. From what I understand, it is because it has a "{" in the formula.
However, that's just how it is entered. (basically, i want it to look in
the
specified cell and place the corresponding value in the selected cell)

Does anyone have a solution to this so that the Macro will run?

Thanks.

Here is the idea of the LOOKUP...
=LOOKUP(I2,{"1","3","5"},{"help","this","the"})



Jacob Skaria

Lookup Function in Macro (VBA)
 
Somthing like this...Try and feedback..

Dim arrLookup As Variant
Dim arrResult As Variant

arrLookup = Array("1", "3", "5")
arrResult = Array("help", "this", "the")
MsgBox WorksheetFunction.Lookup("5", arrLookup, arrResult)


If this post helps click Yes
---------------
Jacob Skaria


"smartguy0753" wrote:

Hi,

I am trying to 'Record a Macro' in the new Excel 2007 that includes the
LOOKUP Function. However, when I finish recording and try to run it, I get
errors. From what I understand, it is because it has a "{" in the formula.
However, that's just how it is entered. (basically, i want it to look in the
specified cell and place the corresponding value in the selected cell)

Does anyone have a solution to this so that the Macro will run?

Thanks.

Here is the idea of the LOOKUP...
=LOOKUP(I2,{"1","3","5"},{"help","this","the"})



All times are GMT +1. The time now is 03:41 PM.

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