"End if without block If" - What does that mean?

easybpw

Active Member
Joined
Sep 30, 2003
Messages
439
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
Can anyone tell me what that means and how I can go about fixing it. It is an error I encountered when running a macro. I'm very confused.

Thanks,

Bill
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
You've got an "END IF" statement without a beginning IF. Something like:
Code:
'your code
End If

when you need
Code:
If Test = 0 Then
'what to do if condition true
Else
'what to do if condition false
End If

Regards,
 
Upvote 0
I had an existing macro that I used as a model for what I wanted to do. I admit freely I practically no clue about complicated macros. This is the macro I used as a model and it works fine:

'Team Total Net Yards
t = 1
Do
t = t + 1
Loop Until Cells(t, 1) = "TOTAL" And _
Cells(t, 2) = "NET" And _
Cells(t, 3) = "YARDS"
tny1 = Cells(t, 4)
tny2 = Cells(t, 5)

End If


I wanted to add some things so I copied this macro (probably not correct anyway but...what do I know) and this is how it all looks now:

'Team Total Net Yards
t = 1
Do
t = t + 1
Loop Until Cells(t, 1) = "TOTAL" And _
Cells(t, 2) = "NET" And _
Cells(t, 3) = "YARDS"
tny1 = Cells(t, 4)
tny2 = Cells(t, 5)

End If

Offset = 1
temp = Cells(c, 1)
If Len(temp) < 4 And Right(temp, 1) = "." Then
temp = temp & Cells(c, 2)
Offset = 2
End If


'Team Net Yards Rushing
t = 1
Do
t = t + 1
Loop Until Cells(t, 1) = "NET" And _
Cells(t, 2) = "YARDS" And _
Cells(t, 3) = "RUSHING"
tny3 = Cells(t, 4)
tny4 = Cells(t, 5)

End If

Offset = 1
temp = Cells(c, 1)
If Len(temp) < 4 And Right(temp, 1) = "." Then
temp = temp & Cells(c, 2)
Offset = 2
End If




So that is what I did, the second half, the code in bold. I'm clueless so any help is appreciated.

Bill
 
Upvote 0
Looks to me like it's the first "End If" in each section. Try this and let us know results.

Code:
'Team Total Net Yards
t = 1
Do
    t = t + 1
Loop Until Cells(t, 1) = "TOTAL" And _
    Cells(t, 2) = "NET" And _
    Cells(t, 3) = "YARDS"

tny1 = Cells(t, 4)
tny2 = Cells(t, 5)

Offset = 1
temp = Cells(c, 1)
If Len(temp) < 4 And Right(temp, 1) = "." Then
    temp = temp & Cells(c, 2)
    Offset = 2
End If


'Team Net Yards Rushing
t = 1
Do
    t = t + 1
Loop Until Cells(t, 1) = "NET" And _
    Cells(t, 2) = "YARDS" And _
    Cells(t, 3) = "RUSHING"

tny3 = Cells(t, 4)
tny4 = Cells(t, 5)

Offset = 1
temp = Cells(c, 1)
If Len(temp) < 4 And Right(temp, 1) = "." Then
    temp = temp & Cells(c, 2)
    Offset = 2
End If

Best regards,
 
Upvote 0
You are missing an If statement in the first part, probably the best thing would be to post the whole subroutine:

Everything between:

Sub and End Sub

Ciao,

Don.
 
Upvote 0
Barrie,

Yes what you gave me got me past my error. Unfortunately I have more errors to figure out. I'm struggling but...

Thanks for the help. I do appreciate it.

Bill
 
Upvote 0
I am getting the same compile error: "End If without Block If". My code is as below.

Please guide. I am not able to figure out how to solve this.
Please help.



Sub Process()
Close
Open "D:\New folder\Plates.txt" For Input As #1
Open "D:\New folder\Output.txt" For Output As #2


Do
For i = 1 To 10000
Line Input #1 , x
xStart = False

If Left(x, 5) = "Plate" Or Left(x, 5) = "Eleme" Then
Print #2 , x
Line Input #1 , x
A$ = x
For j = 1 To 12
Line Input #1 , x
End If

If j = 2 And x = "-65.000" Then
xPrint = True
End If

A$ = A$ & vbTab & x
Next
End If
If xPrint Then Print #2 , A$
End If
xPrint = False

If Left(x, 5) = "(HZ 1" Then
For j = 1 To 13
Line Input #1 , x
Next
End If
Next
Loop
Close
End Sub
 
Upvote 0
You are getting yourself tied up in knots with your "If" statements and your "For" loops

If using nested "For-Next loops" it always helps when using "Next" to include what next it is. eg:
Code:
For j = 1 to 100

Next [COLOR=#ff0000][B]j[/B][/COLOR]

I tried fixing your code but got tied up myself. Having structured code helps dodge these common headaches. so for example, I've used a snippet of your code with correct indentation to help reading:
Code:
Do
    For i = 1 To 10000
        Line Input [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , x
        xStart = False
        If Left(x, 5) = "Plate" Or Left(x, 5) = "Eleme" Then
            Print [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=2]#2[/URL] , x
            Line Input [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , x
            a$ = x
            For j = 1 To 12
                Line Input [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , x
            Next j
        End If
    Next i
Loop
 
Upvote 0
Kind of hard to follow the code without proper indentation but I gave it a go, and here you are.
Rich (BB code):
Sub Process()
Dim i As Long, j As Long, xStart As Boolean
Dim x As String
Dim xPrint As Boolean
Dim A As String

    Close
    Open "D:\New folder\Plates.txt" For Input As #1 
    Open "D:\New folder\Output.txt" For Output As #2 
    
    
    Do
        For i = 1 To 10000
            Line Input #1 , x
            xStart = False
    
            If Left(x, 5) = "Plate" Or Left(x, 5) = "Eleme" Then
                Print #2 , x
                Line Input #1 , x
                A$ = x
                For j = 1 To 12
                    Line Input #1 , x
                Next j
            End If
    
            If j = 2 And x = "-65.000" Then
                xPrint = True
            End If
    
            A$ = A$ & vbTab & x
        
            If xPrint Then Print #2 , A$
    
            xPrint = False
        
            If Left(x, 5) = "(HZ 1" Then
                For j = 1 To 13
                    Line Input #1 , x
                Next j
            End If
            
        Next i
    Loop
    
    Close
    
End Sub

That will compile but I don't know if it'll actually do what you want it to.
 
Upvote 0

Forum statistics

Threads
1,221,023
Messages
6,157,485
Members
451,419
Latest member
jjval01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top