Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    Join Date
    Feb 2013
    Posts
    1

    Red face Same error even i am getting for the following program. Pls help me out.

    Function salary(quantity)

    If quantity <= 25 Then
    salary = 5000 + quantity * 0.25
    Else
    If quantity <= 50 Then
    salary = 10000 + quantity * 0.3
    Else
    salary = 15000 + total_quantity * 0.4

    End If
    End Function

    I am getting the error as "COMPILE ERROR - BLOCKIF WITHOUT ENDIF"
    PLS solve this prob, as i need to complete my project in 2 days.

  2. #17
    Join Date
    Aug 2011
    Posts
    3

    Missing an End If

    Code:
    Function salary(quantity)
    
    If quantity <= 25 Then
        salary = 5000 + quantity * 0.25
        Else
            If quantity <= 50 Then
                salary = 10000 + quantity * 0.3
                Else
                    salary = 15000 + total_quantity * 0.4
            End If
    End If
    
    End Function

  3. #18
    Join Date
    Feb 2013
    Posts
    2

    missing an 'end if' but can't seem to find it

    I have a similar problem. I'm receiving a compile error but can't seem to find the missing 'end if'. Could anyone help me find the error in this code. Sorry for the length.

    Sub add_app()
    'Renaming for coding purposes
    Dim historyWks As Worksheet
    Dim inputWks As Worksheet

    Dim nextrow As Long
    Dim oCol As Long
    Dim transaction_info As Range
    Dim lRsp As Long
    Dim mycopy As Range
    Dim IRsp2 As Long
    Dim mytest As Range

    Set inputWks = Worksheets("sheet1")
    Set historyWks = Worksheets("all-rdr")
    oCol = 1 'order info is pasted on data sheet, starting in this column

    'check for duplicate when sending and receiving match
    If inputWks.Range("checkapns") = True And inputWks.Range("checkapnr") = True Then
    lRsp = MsgBox("Transfer already in database. Update record?", vbQuestion + vbYesNo, "Duplicate ID")
    If lRsp = vbYes Then
    UpdateLogRecord
    Else
    MsgBox "Please change APN number"
    End If
    'check for duplicate sending
    If inputWks.Range("checkapns") = True And inputWks.Range("checkapnr") = False Then
    lRsp = MsgBox("You are about to update existing sending site data. Would you like to continue?", vbQuestion + vbYesNo, "Duplicate ID")
    If lRsp = vbYes Then
    IRsp2 = MsgBox("Will this utilize all remaining rights from the sending site?", vbQuestion + vbYesNo)
    If IRsp2 = vbYes Then
    UpdateLogRecord
    Else
    add_app
    End If

    Else

    'cells to copy from Input sheet - some contain formulas
    Set mycopy = inputWks.Range("transaction_info")

    With historyWks
    nextrow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row
    End With

    With inputWks
    'mandatory fields are tested in hidden column
    Set mytest = mycopy.Offset(0, 1)

    If Application.Count(mytest) > 0 Then
    MsgBox "Please fill in all the cells!"
    Exit Sub
    End If
    End With

    With historyWks
    'enter date and time stamp in record
    With .Cells(nextrow, "Q")
    .Value = Now
    .NumberFormat = "mm/dd/yyyy, hh:mm"
    End With
    'enter user name in column B
    .Cells(nextrow, "R").Value = Application.UserName

    'copy the order data and paste onto data sheet
    transaction_info.Copy
    .Cells(nextrow, "A").PasteSpecial Paste:=xlPasteValues, Transpose:=True
    Application.CutCopyMode = False
    End With

    'clear input cells that contain constants
    ClearDataEntry
    End If

    End Sub

  4. #19
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    can you repost the code inside [ c o d e ] & [ / c o d e ] blocks (without the spaces)
    can you make certain the code is indented, especially if / then statements, with/end withg and so on

    eg:-
    Code:
    'check for duplicate when sending and receiving match
    If inputWks.Range("checkapns") = True And inputWks.Range("checkapnr") = True Then
      lRsp = MsgBox("Transfer already in database. Update record?", vbQuestion + vbYesNo,   "Duplicate ID")
    endif
    If lRsp = vbYes Then
      UpdateLogRecord
    Else
      MsgBox "Please change APN number"
    End If
    I'd rather be riding on the Tiger 800 or the Norton

  5. #20
    Join Date
    Feb 2013
    Posts
    2
    sure can. I'm a first time board user so I hope this posts right...

    Code:
    Sub add_app()
    'Renaming for coding purposes
        Dim historyWks As Worksheet
        Dim inputWks As Worksheet
    
        Dim nextrow As Long
        Dim oCol As Long
        Dim transaction_info As Range
        Dim lRsp As Long
        Dim mycopy As Range
        Dim IRsp2 As Long
        Dim mytest As Range
    
        Set inputWks = Worksheets("sheet1")
        Set historyWks = Worksheets("all-rdr")
        oCol = 1 'order info is pasted on data sheet, starting in this column
        
        'check for duplicate when sending and receiving match
        If inputWks.Range("checkapns") = True And inputWks.Range("checkapnr") = True Then
          lRsp = MsgBox("Transfer already in database. Update record?", vbQuestion + vbYesNo, "Duplicate ID")
          If lRsp = vbYes Then
            UpdateLogRecord
          Else
            MsgBox "Please change APN number"
          End If
           'check for duplicate sending
        If inputWks.Range("checkapns") = True And inputWks.Range("checkapnr") = False Then
          lRsp = MsgBox("You are about to update existing sending site data. Would you like to continue?", vbQuestion + vbYesNo, "Duplicate ID")
          If lRsp = vbYes Then
          IRsp2 = MsgBox("Will this utilize all remaining rights from the sending site?", vbQuestion + vbYesNo)
          If IRsp2 = vbYes Then
            UpdateLogRecord
          Else
           add_app
          End If
          
        Else
    
          'cells to copy from Input sheet - some contain formulas
          Set mycopy = inputWks.Range("transaction_info")
          
          With historyWks
              nextrow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row
          End With
       
       With inputWks
              'mandatory fields are tested in hidden column
              Set mytest = mycopy.Offset(0, 1)
      
              If Application.Count(mytest) > 0 Then
                  MsgBox "Please fill in all the cells!"
                  Exit Sub
              End If
          End With
          
          With historyWks
              'enter date and time stamp in record
              With .Cells(nextrow, "Q")
                  .Value = Now
                  .NumberFormat = "mm/dd/yyyy, hh:mm"
              End With
              'enter user name in column B
              .Cells(nextrow, "R").Value = Application.UserName
              
              'copy the order data and paste onto data sheet
                transaction_info.Copy
              .Cells(nextrow, "A").PasteSpecial Paste:=xlPasteValues, Transpose:=True
              Application.CutCopyMode = False
          End With
          
          'clear input cells that contain constants
          ClearDataEntry
        End If
      
    End Sub

  6. #21
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so having indented the code are there any obvious if then blocks that aren't terminated by an endif?

    bear in mind that VB does allow
    Code:
    if (condition) then statement
    as a valid statement without an endif. but I'd strongly reccommned that you never EVER use that style as it can make tracing erros liek this harder


    if you are still struggling then a technique that I have seen work is to comment the endif or else statements

    eg
    Code:
        If inputWks.Range("checkapns") = True And inputWks.Range("checkapnr") = True Then
          lRsp = MsgBox("Transfer already in database. Update record?", vbQuestion + vbYesNo, "Duplicate ID")
          If lRsp = vbYes Then
            UpdateLogRecord
          Else 'lRsp wasn't so tell the t(*&)(*t to change the APn number
            MsgBox "Please change APN number"
          End If 'finished checking the user response
        [red]End if[/red]
    I'd rather be riding on the Tiger 800 or the Norton

  7. #22
    Join Date
    Aug 2011
    Posts
    3

    not sure if you got your question answered but..

    Quote Originally Posted by Cbc-database View Post
    I have a similar problem. I'm receiving a compile error but can't seem to find the missing 'end if'. Could anyone help me find the error in this code. Sorry for the length.
    Looks to me as if you are missing two END IF statements - generally when building an IF Then Else End IF structure I will enter all those lines first then go put the code in between - it also helps to indent code so that you can see how things are nested. Comments can also be helpful.

    in the snippet below you may have to scroll over to the right to see where I added tags for each If and End IF statement.
    Code:
    Sub add_app()
    'Renaming for coding purposes
        Dim historyWks As Worksheet
        Dim inputWks As Worksheet
    
        Dim nextrow As Long
        Dim oCol As Long
        Dim transaction_info As Range
        Dim lRsp As Long
        Dim mycopy As Range
        Dim IRsp2 As Long
        Dim mytest As Range
    
        Set inputWks = Worksheets("sheet1")
        Set historyWks = Worksheets("all-rdr")
        oCol = 1 'order info is pasted on data sheet, starting in this column
        
        'check for duplicate when sending and receiving match
        If inputWks.Range("checkapns") = True And inputWks.Range("checkapnr") = True Then                               ' IF A
          lRsp = MsgBox("Transfer already in database. Update record?", vbQuestion + vbYesNo, "Duplicate ID")
          If lRsp = vbYes Then                                                                                                                                              ' IF B
            UpdateLogRecord
          Else
            MsgBox "Please change APN number"
          End If                                                                                                                                                                     ' END IF B
           'check for duplicate sending
        
        
        ' should END IF A be here? or at the very end ?
        
        
        If inputWks.Range("checkapns") = True And inputWks.Range("checkapnr") = False Then                                 ' IF C
          lRsp = MsgBox("You are about to update existing sending site data. Would you like to continue?", vbQuestion + vbYesNo, "Duplicate ID")
          If lRsp = vbYes Then                                                                                                                                       ' IF D
          IRsp2 = MsgBox("Will this utilize all remaining rights from the sending site?", vbQuestion + vbYesNo)
            If IRsp2 = vbYes Then                                                                                                                                         ' IF E
              UpdateLogRecord
            Else
             add_app
            End If                                                                                                                                                                  ' END IF E
          
        Else
    
          'cells to copy from Input sheet - some contain formulas
          Set mycopy = inputWks.Range("transaction_info")
          
          With historyWks
              nextrow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row
          End With
      
      
      ' should END IF C or END IF D be here?
      
      
       With inputWks
              'mandatory fields are tested in hidden column
              Set mytest = mycopy.Offset(0, 1)
      
              If Application.Count(mytest) > 0 Then                                                                                                             ' IF F
                  MsgBox "Please fill in all the cells!"
                  Exit Sub
              End If                                                                                                                                                                ' END IF F
          End With
          
          With historyWks
              'enter date and time stamp in record
              With .Cells(nextrow, "Q")
                  .Value = Now
                  .NumberFormat = "mm/dd/yyyy, hh:mm"
              End With
              'enter user name in column B
              .Cells(nextrow, "R").Value = Application.UserName
              
              'copy the order data and paste onto data sheet
                transaction_info.Copy
              .Cells(nextrow, "A").PasteSpecial Paste:=xlPasteValues, Transpose:=True
              Application.CutCopyMode = False
          End With
          
          'clear input cells that contain constants
          ClearDataEntry
        End If                                                                                                                                                                  ' END IF ??? A ???
      
    End Sub

  8. #23
    Join Date
    Jun 2017
    Location
    Ukraine
    Posts
    11

    Compile Error Block IF without END IF

    Trying to compile this morning I get the following error from cmake. Any idea what might be wrong?

    Code:

Posting Permissions

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