Simpkify ISNA and VLOOKUP code in macro

forest2m

New Member
Joined
Sep 23, 2008
Messages
37
Hello All,
I have this macro code:
Code:
Cells(i, 27).FormulaR1C1 = "=ISNA(VLOOKUP(RC[-23]&""-""&RC[-19], '[Helper File.xls]Lookup'!C1:C1,1,0))"
I would like to simplify it to no longer use the R1C1 syntax. I'd like to do something similar to the following:
Code:
VariableName = Application.WorksheetFunction.VLookup(Range(Cells(i, 3)).Value & "-" & Range(Cells(i, 13)).Value, '[Helper File.xls]Lookup'!C1:C1, 1, True)
That code doesn't work, of course, and it also doesn't include the ISNA portion. I'd like to have the variable hold the TRUE or FALSE result of the ISNA.
The first part of the VLOOKUP is a concatenated value, with a hyphen between the values, such as 10-223. I need to lookup data in Column C on the Lookup sheet in the Helper File. Any ideas?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
even though it is possible to introduce a formula containing variables in excel vbal I find it tricky to correctly use the quotes and variables.
so I rewrite the macro and use find method to get the relevan reference value and offset to get at the particular column value.
anyhow sometime back I did this macro which uses application.vlookup(instead of worksheetfunction.vlookup
see whether you can modify it to suity you . you can incorporate if na into it. if necessary please post a very small extract of your sheet and deails of what you want.

Code:
'this is another way of filling navs to desired mfs
'using variable in the lookup value in vlookup funciton. 
'instead of vba forumual you use appliation method. 
'instead of naming the nav table you uses set method

Public Sub test()
Dim navtable As Range
Dim myrange As Range
    Worksheets("sheet1").Activate
Set navtable = ActiveSheet.UsedRange
    Sheet2.Activate
Dim mfone As Range
Dim mflast As Range
     Set mfone = Range("a6")
    Set mflast = Range("a6").End(xlDown)
        Set myrange = Range(mfone, mflast)
    For Each c In myrange
    c.End(xlToRight).Offset(0, 1) = Application.VLookup(c, navtable, 3, False)
    Next
End Sub
 
Upvote 0
try
Code:
Dim myVariable As Boolean
myVariable = IsError(Application.VLookup(Range(Cells(i, 3)).Value & "-" & Range(Cells(i, 13)).Value, _
Workbooks("Helper File.xls").Sheets("Lookup").Range("a:a"), 1, True))
 
Upvote 0
Re: Simplify ISNA and VLOOKUP code in macro

Thank you both for your replies. I was able to use Seiya's code, but had to modify it as follows:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
Rich (BB code):
myVariable = IsError(Application.VLookup(Cells(i, 3).Value & "-" & Cells(i, 13).Value, _
Rich (BB code):
Workbooks("Helper File.xls").Sheets("Lookup").Range("A:A"), 1, False))
<o:p></o:p>
The first argument of the VLOOKUP had to be modified (I'm not sure why, but the Range part didn't work), and the last argument had to be changed to False so I would only get exact matches.<o:p></o:p>
<o:p></o:p>
I have 2 more questions:<o:p></o:p>
How do I return the value of the VLOOKUP itself, not the error portion? I tried simply removing the IsError() and changing the variable to String, instead of Boolean, but I got an error message.<o:p></o:p>
<o:p></o:p>
Does anyone know of a good resource that lists the different syntax for Cells, Range, Row, Column, etc? I know these can be used with numbers and variables, like Cells(i, 3).Value, or with quotes, like Range("A:A"), or with the R1C1 syntax. I'd like to see the rules on how to use all of those variations. I'd also like a list of the objects that can be used with these methods, such as .Value, .EntireColumn.Delete, etc.<o:p></o:p>
<o:p></o:p>
Thanks again!<o:p></o:p>
 
Upvote 0
Re: Simplify ISNA and VLOOKUP code in macro

Sorry the code broke into 2 parts in my last post. It should be:
Rich (BB code):
myVariable = IsError(Application.VLookup(Cells(i, 3).Value & "-" & Cells(i, 13).Value, Workbooks("Helper File.xls").Sheets("Lookup").Range("A:A"), 1, False))
 
Upvote 0
Re: Simplify ISNA and VLOOKUP code in macro

1) Declare myVariable as Variant, since it may return any type of value.
2) You can get all the method/properties though automatically when you write object like
Code:
Sheets("sheet1").
Range("a1").
Cells(1).
You should see the list when you type a period after the object.

Or browse the object browser.
In VBE
[View] - [Object Browser]
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,429
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top