Announcement

Collapse
No announcement yet.

Compile error. End if without block if

Collapse
This topic is closed.
X
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Compile error. End if without block if



    I have just written the following code for an I.T project.

    Code:
     Sub UPDATE()
    
    Dim temp As Integer 'stock_list is the current stock level used to avoid errors such as adjusting itself
    Dim row_stock   As Integer 'row_stock is the row in thew stock list of the current product
    Dim row_invoice As Integer 'row_invoice is the row in the invoice
    
    For row_stock = 4 To 28
    For row_invoice = 14 To 30
    
    If Worksheets("stock").Cells(row_stock, "A").Value = Worksheets("Invoice").Cells(row_invoice, "A").Value Then temp = Worksheets("Stock List").Cells(row_stock, "E").Value
        Worksheets("Stock List").Cells(row_stock, "F").Value = temp - Worksheets("Invoice").Cells(row_invoice, "F").Value
    End If
    
    Next row_invoice
    
    Next row_stock
    
    End Sub
    For some reason my I.T teacher cant help me. Its coming up with an error saying

    compile error:
    End If without Block If
    Any help will be appreciated. Thanks
    Last edited by ajclarke; September 9th, 2005, 19:22. Reason: Title not good enough apparently!

  • #2
    Re: Vba?

    Please read the rules you agreed to particularly concerning Thread Titles. Thanks. You need to amend your title to something more meaningful
    Hope that Helps

    Roy

    New users should read the Forum Rules before posting

    For free Excel tools & articles visit my web site

    RoyUK's Web Site

    royUK's Database Form

    Where to paste code from the Forum

    About me.

    Comment


    • #3
      Re: Vba?

      Easy.

      If you want to execute more than one statement after an if, you *must* not put the first of those statements on the If line (IYSWIM)

      so:

      Code:
       if <test> then
      do this
      do that
      do the other
      end if
      ...will work...

      but

      Code:
       if <test > then do this
      do that
      do the other
      end if
      will return the error you have seen.

      If there is *only* one action as a result of the If, it should be on the same line and you don't need the end if:

      Code:
      if <test> then <Do Only This>
      HTH

      <edited to say>Ignore the horrible indentation in my code - it's because I type the pseudo code direct into the post - I don't normally indent like that... ;o)

      Comment


      • #4
        Re: Vba?

        Hi ajclark

        Welcome to ozgrid

        Please use more meaningful Thread Title. "VBA" is of no help for searching or answering your question.

        Change to:
        Code:
                    If Worksheets("stock").Cells(row_stock, "A").Value = Worksheets("Invoice").Cells(row_invoice, "A").Value Then
                        temp = Worksheets("Stock List").Cells(row_stock, "E").Value
                        Worksheets("Stock List").Cells(row_stock, "F").Value = temp - Worksheets("Invoice").Cells(row_invoice, "F").Value
                    End If

        Comment


        • #5
          Re: Compile error. End if without block if

          NOw its giving me a runtime error 9? saying subscript out of range

          Comment


          • #6


            Re: Compile error. End if without block if

            I'm locking your post until you read and agree to the rules

            Comment

            Working...
            X