Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 50
Default Temp variables within formulas?

Here's a common example: you want a formula with a VLOOKUP which either looks
up the number you want, or returns zero if it's not in the table -- this is
so that calculations based on that formula use zero and calculate something
meaningful rather than result in #N/A!. So you have to do this:

IF(ISNA(VLOOKUP(...)),0,VLOOKUP(...))

Of course that "..." can be pretty long and hairy. And it's inefficient
too, because that long VLOOKUP has to be calculated twice. Isn't there any
way of writing a formula so it calculates the VLOOKUP once, stored the
result, and uses just the result in the rest of the formula? That is:

R=VLOOKUP(...);IF(ISNA(R),0,R)

I realize you can insert columns just to hold temporary results, and then
hide them, but when you copy them and paste them outside Excel, you get the
hidden columns too, and I don't want them.

Thanks!

--
Andy Smith
Senior Systems Analyst
Standard & Poor's, NYC

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Temp variables within formulas?

MS had the same thoughts of you and introduced the =iferror() function in
xl2007.



Andy Smith wrote:

Here's a common example: you want a formula with a VLOOKUP which either looks
up the number you want, or returns zero if it's not in the table -- this is
so that calculations based on that formula use zero and calculate something
meaningful rather than result in #N/A!. So you have to do this:

IF(ISNA(VLOOKUP(...)),0,VLOOKUP(...))

Of course that "..." can be pretty long and hairy. And it's inefficient
too, because that long VLOOKUP has to be calculated twice. Isn't there any
way of writing a formula so it calculates the VLOOKUP once, stored the
result, and uses just the result in the rest of the formula? That is:

R=VLOOKUP(...);IF(ISNA(R),0,R)

I realize you can insert columns just to hold temporary results, and then
hide them, but when you copy them and paste them outside Excel, you get the
hidden columns too, and I don't want them.

Thanks!

--
Andy Smith
Senior Systems Analyst
Standard & Poor's, NYC


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,572
Default Temp variables within formulas?

There have been discussions (prior to XL07) in these groups about the
efficiency of various other functions over the double use of Vlookup as an
error trap.

Match() and Countif() being just a couple.

=If(ISNA(Match(D1,A1:A100,0)),0,Vlookup(D1,A1:C100 ,3,0))

=If(Countif(A1:A100,D1),Vlookup(D1,A1:C100,3,0),0)

And, if you're copying the Vlookup formula across many columns in order to
return numerous fields of a datalist,
you could use a single cell to calculate the existence of a match, and
simply refer to that cell before performing the Vlookup.

In E1:
=COUNTIF(A1:A100,D1)

Then:
=If($E$10,Vlookup(D1,$A$1:$C$100,3,0),0)


--

Regards,

RD
-----------------------------------------------------------------------------------------------
Please keep all correspondence within the Group, so all may benefit !
-----------------------------------------------------------------------------------------------


"Andy Smith" wrote in message
...
Here's a common example: you want a formula with a VLOOKUP which either
looks
up the number you want, or returns zero if it's not in the table -- this is
so that calculations based on that formula use zero and calculate something
meaningful rather than result in #N/A!. So you have to do this:

IF(ISNA(VLOOKUP(...)),0,VLOOKUP(...))

Of course that "..." can be pretty long and hairy. And it's inefficient
too, because that long VLOOKUP has to be calculated twice. Isn't there any
way of writing a formula so it calculates the VLOOKUP once, stored the
result, and uses just the result in the rest of the formula? That is:

R=VLOOKUP(...);IF(ISNA(R),0,R)

I realize you can insert columns just to hold temporary results, and then
hide them, but when you copy them and paste them outside Excel, you get the
hidden columns too, and I don't want them.

Thanks!

--
Andy Smith
Senior Systems Analyst
Standard & Poor's, NYC


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
Problem using obj.Namespace(sourceFileName) Namespace(DestinationFilename).Itemsand then opening the xls file which creates a Temp Folder inside Temp Yuvraj Excel Discussion (Misc queries) 3 May 3rd 09 11:59 AM
Variables in formulas build Excel Worksheet Functions 9 October 11th 07 12:35 PM
What if < with multiple variables and formulas Anna Excel Discussion (Misc queries) 3 July 18th 07 03:54 PM
Using formulas to source a value based on 2 variables bsmith69 Excel Worksheet Functions 2 June 14th 06 11:12 PM
How can I use variables in formulas in VB? thorsten Excel Discussion (Misc queries) 2 May 16th 06 08:22 PM


All times are GMT +1. The time now is 08:33 AM.

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"