+ Reply to Thread
Results 1 to 4 of 4

If Then Statement help

Hybrid View

  1. #1
    Registered User
    Join Date
    10-21-2013
    Location
    Indianapolis, IN
    MS-Off Ver
    Excel 2013
    Posts
    4

    If Then Statement help

    I keep getting an error message for this function:

    Function Gear(RPM As Double, Gear1 As Double)
       If RPM >= 7200 And Gear1 = 1 Then
            Gear = 2
        If RPM >= 7200 And Gear1 = 2 Then
            Gear = 3
        If RPM >= 7200 And Gear1 = 3 Then
            Gear = 4
        If RPM >= 7200 And Gear1 = 4 Then
            Gear = 5
        If RPM >= 7200 And Gear1 = 5 Then
            Gear = 6
        If RPM >= 7200 And Gear1 = 6 Then
            Gear = 6
        Else
            Gear = Gear1
            
        End If
            
    End Function
    I'm not sure what's wrong with the function. Error says Block End If.
    Last edited by Fotis1991; 10-21-2013 at 08:28 AM. Reason: Pls use code tags around your code.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: If Then Statement help

    Function Gear(RPM As Double, Gear1 As Double)
    
     If RPM >= 7200 And Gear1 = 1 Then
           Gear = 2
            If RPM >= 7200 And Gear1 = 2 Then
                 Gear = 3
                If RPM >= 7200 And Gear1 = 3 Then
                   Gear = 4
                    If RPM >= 7200 And Gear1 = 4 Then
                       Gear = 5
                        If RPM >= 7200 And Gear1 = 5 Then
                           Gear = 6
                            If RPM >= 7200 And Gear1 = 6 Then
                                Gear = 6
                            Else
                                Gear = Gear1
    
                            End If
                        End If
                    End If
                End If
            End If
     End If
    End Function
    Last edited by AB33; 10-21-2013 at 08:34 AM.

  3. #3
    Registered User
    Join Date
    10-21-2013
    Location
    Indianapolis, IN
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: If Then Statement help

    Thanks, I tried that. Now I just get a zero value for the function. I'm not sure if I defined the inputs wrong or what. RPM is between 3000 and 7200. Gear1 is between 1.45 and 3.20.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: If Then Statement help

    You are probably getting this line

    Gear = Gear1
    Since your gear starts at 1, the else may return 0.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA Compile Error : line number or label or statement or end of statement
    By excellearner121 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-04-2013, 06:41 PM
  2. Replies: 4
    Last Post: 06-01-2012, 10:05 AM
  3. Replies: 4
    Last Post: 05-16-2012, 05:33 PM
  4. Have question about using .find statement and brackets around After:= statement
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-09-2011, 03:28 PM
  5. [SOLVED] Utilize a Select Case Statement in Target Intersect Statement
    By max57 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-29-2009, 08:55 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1