none
Else If evaluating before If RRS feed

  • Question

  • Function BassFix(H, V)

    If H = 0 And V > 0 Then  //If this code is by itself it evaluates fine
    B = 90

    ElseIf H = 0 And V < 0 Then  //If I add this code, it evaluates and the first statement stops working
    B = 270

    //How can this happen if the first line is evaluating first? How can the ElseIf take over

    //I can't use an else because I need only these two conditions to be evaluated

    BassFix = B
    End If

    End Function

    Friday, November 20, 2015 5:45 PM

All replies

  • Re:  function syntax

    Try it this way...
    '---
    Function BassFix(H, V)
     Dim B As Variant

     If H = 0 And V > 0 Then
       B = 90
     ElseIf H = 0 And V < 0 Then
       B = 270
     Else
       B = 0          ' Used as a flag
     End If
     BassFix = B   '<<< Note placement
    End Function

    '---
    Jim Cone
    Portland, Oregon USA
    https://goo.gl/IUQUN2 (Dropbox)
    (free & commercial excel add-ins & workbooks)
    • Edited by James Cone Tuesday, October 25, 2016 1:34 AM
    Friday, November 20, 2015 7:37 PM