Is this the most efficient formula

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
16,813
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Hi all,
I have the Vlookup formula below. Now it is working correctly but the question I have is this the most efficient way of doing this?

It is obviously performing 3 Vlookups to get the desired result (i.e. turning all errors and value 0 to "Not Set") and this gives me concerns over whether it the most efficient way of achieving it.

Unfortunately it does need to work with 2003.

Any pointers anyone can give would be much appreciated.
Formula
=IF(ISERROR(VLOOKUP(A2,Sheet3!A:M,9,0)),"Not Set",IF(VLOOKUP(A2,Sheet3!A:M,9,0)=0,"Not Set",VLOOKUP(A2,Sheet3!A:M,9,0)))
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
You could use this function
=IF(ISERROR(VLOOKUP(A2,Sheet3!A1:M1000,9,0)), "Not Set", VLOOKUP(A2,Sheet3!A1:M1000,9,0))

and format the cell with the custom format General;-General;"Not Set"

The use of a not-whole-column reference will speed things up.
 
Upvote 0
If you need the value in the cell to actually contain the text "Not Set". not just as the result of formatting, you could use the following, which replaces one vlookup with a countif, and gets rid of one nested if. I really don't know if there would be any noticeable difference in efficiency; it's just a different way to accomplish the same end result.
Code:
=IF(OR(COUNTIF(Sheet3!A:A,Sheet1!A2)=0,VLOOKUP(Sheet1!A2,Sheet3!A1:M1000,9,0)=0),"Not Set",VLOOKUP(Sheet1!A2,Sheet3!A1:M1000,9,0))
If this formula will be copied down or across to multiple cells, be sure to use $ with the row and column in the VLOOKUP's (e.g. $A$1:$M$1000).

Hope that helps,

Cindy
 
Upvote 0
Hi all,
I have the Vlookup formula below. Now it is working correctly but the question I have is this the most efficient way of doing this?

It is obviously performing 3 Vlookups to get the desired result (i.e. turning all errors and value 0 to "Not Set") and this gives me concerns over whether it the most efficient way of achieving it.

Unfortunately it does need to work with 2003.

Any pointers anyone can give would be much appreciated.
Formula
=IF(ISERROR(VLOOKUP(A2,Sheet3!A:M,9,0)),"Not Set",IF(VLOOKUP(A2,Sheet3!A:M,9,0)=0,"Not Set",VLOOKUP(A2,Sheet3!A:M,9,0)))
On Excel 2007 or later and a text result is expected...

=IFERROR(T(VLOOKUP(A2,Sheet3!A:M,9,0)),"Not Set")

On all versions and a text result is expected...

=LOOKUP(REPT("z",255),CHOOSE({1,2},"Not Set",T(VLOOKUP(A2,Sheet3!A:M,9,0))))

If the table area in A:M on Sheet3 is or can be sorted on column A, a much faster option is possible.

Also, if whole column references are not necessary, try the use exact ranges. Otherwise, a dynamic named range would be appropriate.
 
Upvote 0
Thanks for the reply Mike.
I am afraid I will have trouble with not using the whole-column reference as the sheet is pulled in from the company system via a text file using a macro and number of rows varies twice weekly (Basically it is a listing of all the product lines in the company and last time I can remember it stood at 13800+ product codes. By April each year it normally stands at approx. 26000) and so I will have to set it at 30000 to play safe.
Is it worth it with a number so high?
The formula in the first posting is in a macro with a fill down to last row in a results sheet. The source sheet is again pulled in via a macro
What I am thinking though is using a find and replace code on the source sheet to change the 0 values to "Not set" at that stage, which will cause it to appear as an error in the result sheet but at least that means there will be only the 2 Vlookups needed on the errors.
Do you think this method will give any efficiency saving or would it negligible?
 
Upvote 0
Yes it is worth setting it that high.
Its also worth using a dynamic named range, like:

Name: dataRange
RefersTo: Sheet3!$M$1:INDEX(Sheet3!$A:$A, COUNTA(Sheet3!$A:$A), 1)

with the formulas altered like
=IF(ISERROR(VLOOKUP(A2,dataRange,9,0)), "Not Set", VLOOKUP(A2,dataRange,9,0))

If you have blank rows in Sheet3!A:A, the defintion of the named range will need to be altered.
 
Upvote 0
Cindy, thanks for your response I will give it some testing to see if it is more or less efficient but probably not until tomorrow at work when i can test it on somebodies 2003 version

Aladin, thanks for your response. Unfortunately I do need the values from the cells not involved in the "Not Set" criteria. the not set text with the 0 is basically there to take it out of a future less than formula. On your question of the sorting on Sheet3. That wouldn't be a problem.

Mike, I am just reading through your latest suggestion. I will post back once I have given it a try

Again, thanks for all the replies
 
Upvote 0
...
Aladin, thanks for your response. Unfortunately I do need the values from the cells not involved in the "Not Set" criteria. the not set text with the 0 is basically there to take it out of a future less than formula.

I don't understand this part. Are you referring to using the T() function?

On your question of the sorting on Sheet3. That wouldn't be a problem.
...

Well, this is good news...

Either:
Code:
=IF(LOOKUP(A2,Sheet3!A:A)=A2,
     T(LOOKUP(A2,Sheet3!A:A,Sheet3!I:I),"Not Set")

Or:
Code:
=IF(LOOKUP(A2,Sheet3!A:A)=A2,
     IF(LOOKUP(A2,Sheet3!A:A,Sheet3!I:I)="",
        "Not Set",
        LOOKUP(A2,Sheet3!A:A,Sheet3!I:I);
     "Not Set")
 
Upvote 0
Mike, I have tried your latest posting manually and it seems to be working well. I have to work out how to put the dynamic named range into a macro but I am sure the recorder will get me there.

Aladin
I don't understand this part. Are you referring to using the T() function?
What I was referring to is the result I was looking for was a result as per Column Y but the solution you gave was as per column Z. I.e. the numbers were not there.

Excel Workbook
YZ
1**
2112*
3112*
4720*
5720*
6Not SetNot Set
7Not SetNot Set
8Not SetNot Set
9Not SetNot Set
10Not SetNot Set
11Not SetNot Set
12Not SetNot Set
13Not SetNot Set
14Not SetNot Set
15300*
16300*
Sheet2


I am going with Mikes solution (as long as I can convert it to VBA) as I think that is going to be the way to go.

I thank all three of you for your work on this (In particular Mike for what is hopefully the final solution). As always the help given on this site is invaluable
 
Upvote 0
Mike, I have tried your latest posting manually and it seems to be working well. I have to work out how to put the dynamic named range into a macro but I am sure the recorder will get me there.

Aladin

What I was referring to is the result I was looking for was a result as per Column Y but the solution you gave was as per column Z. I.e. the numbers were not there.

...

I really understand this at all. Neither post #4 nor post #8 has anything on column Y or column Z. Moreover, the latter gives you the most efficient approach if the sorting as you said is not a problem.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

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