PDA

View Full Version : Execute diferent formula depending on cell value



zale86
11-03-2009, 09:25 AM
I want to execute one of five different formulas depending on the value of a given cell which would be between 1 and 5. Can someone point me in the right direction?
thanks in advance

Bob Phillips
11-03-2009, 10:47 AM
Try

=IF(M1=1,formula1,IF(M1=2,formula2, etc.

ColinJohnson
11-03-2009, 12:33 PM
A regular If,Then statement might be your best bet but if you were looking to create your own Function it might look something like this:

Function VBAPost(Value)

If Value = 1 Then
VBAPost = 'Formula #1 here

ElseIf Value = 2 Then
VBAPost = 'Formula #2 here

ElseIf Value = 3 Then
VBAPost = 'Formula #3 here

ElseIf Value = 4 Then
VBAPost = 'Formula #4 here

ElseIf Value = 5 Then
VBAPost = 'Formula #5 here

End If

End Function

If you're not comfortable enough writing in VBA then your best bet would be to use the prepackaged IF() function as xld suggested.

zale86
11-03-2009, 12:42 PM
Thanks, got it