Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default Versatile "adaptive" formulae? (instead of "hard"coded IF tests)

Hello,
I would like to setup a formula using a IF() statement that can be
customized
based on a definition set in a particular cell instead of being hard-
coded.
eg I don't mean just a custom VALUE but also a custom TEST.
Can this be done?

Let's say I have a formula 1:
IF(LEFT(A1)=a),"yes","no")

if I now want to change the formula to a new formula 2:
IF(RIGHT(A1)=b),"yes","no")

instead of manually rewriting the formula, I'd like to just define
the test and value to be used in a separate cell and refer to it.

Example:

- cell A1 contains the data to be tested.
- cell A10 contains the "TEST": for example LEFT()
- cell A11 contains the "VALUE", for example "a"
the formula should be (pseudocode):
IF("test specified in $A$10 applied on" (A1)=$A$11, "yes","no").

If I now want to apply "formula 2", I would just need to modify cells
A10 and A11:
A10 - RIGHT() (or any other formula of course)
A11 - b

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,856
Default Versatile "adaptive" formulae? (instead of "hard"coded IF tests)

Here is a User-defined function:

Function eval(func As String)
Application.Volatile
eval = Evaluate(func)
End Function

This will take a string and evaluate it as if it were a normal
formula. So, for example, put the text 2 + 4 in A1, and then in A2
enter this formula:

=eval(A1)

and you will get 6 as a result.

So what you will need to do is to build up your string as a
syntactically correct Excel formula and then just pass it to the eval
function to get the result.

Hope this helps.

Pete


On Oct 5, 6:00 pm, MCSmarties wrote:
Hello,
I would like to setup a formula using a IF() statement that can be
customized
based on a definition set in a particular cell instead of being hard-
coded.
eg I don't mean just a custom VALUE but also a custom TEST.
Can this be done?

Let's say I have a formula 1:
IF(LEFT(A1)=a),"yes","no")

if I now want to change the formula to a new formula 2:
IF(RIGHT(A1)=b),"yes","no")

instead of manually rewriting the formula, I'd like to just define
the test and value to be used in a separate cell and refer to it.

Example:

- cell A1 contains the data to be tested.
- cell A10 contains the "TEST": for example LEFT()
- cell A11 contains the "VALUE", for example "a"
the formula should be (pseudocode):
IF("test specified in $A$10 applied on" (A1)=$A$11, "yes","no").

If I now want to apply "formula 2", I would just need to modify cells
A10 and A11:
A10 - RIGHT() (or any other formula of course)
A11 - b



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
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM
Complex if test program possible? If "value" "value", paste "value" in another cell? jseabold Excel Discussion (Misc queries) 1 January 30th 06 10:01 PM
Insert "-" in text "1234567890" to have a output like this"123-456-7890" Alwyn Excel Discussion (Misc queries) 3 October 25th 05 11:36 PM


All times are GMT +1. The time now is 09:22 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"