Consulting

Results 1 to 4 of 4

Thread: Execute diferent formula depending on cell value

  1. #1
    VBAX Regular
    Joined
    Feb 2009
    Posts
    7
    Location

    Execute diferent formula depending on cell value

    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try

    =IF(M1=1,formula1,IF(M1=2,formula2, etc.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    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.

  4. #4
    VBAX Regular
    Joined
    Feb 2009
    Posts
    7
    Location
    Thanks, got it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •