VBA - Compile error: 'Block If without End If'

MrAbc

New Member
Joined
Dec 28, 2011
Messages
6
I have entered this code in excel:

Sub KS3_NewTask()
Dim lColNo As Long

Dim blast As Boolean, bFound As Boolean

For lColNo = 1 To 150

If Columns(lColNo).Hidden Then
If blast Then
'---1ColNo is Col 2 of 4 for Task
bFound = True
Exit For
End If
End If
blast = Columns(lColNo).Hidden
Next lColNo
If bFound Then
'---unhide Cols 1,2,4 of Task
Columns(lColNo - 1).Resize(, 2).Hidden = False
Columns(lColNo + 2).Hidden = False
End Sub

I am new to it and have copied this code off a friend so not a 100% sure if correct, but i get an error message that says 'Block If without end If'. Not sure what it means, can you please show me how to sort it out?
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Put End If just before End Sub
 
Upvote 0
Hi and welcome to the Board
You are missing an End IF after the second line here
Rich (BB code):
Columns(lColNo - 1).Resize(, 2).Hidden = False
Columns(lColNo + 2).Hidden = False
 End If
End Sub
These mistakes will be easier to find if you Indent your code
 
Upvote 0
Note how the code is easier to follow with indentation..
Also try to use code tags when posting
Code:
Sub KS3_NewTask()
Dim lColNo As Long, blast As Boolean, bFound As Boolean
    For lColNo = 1 To 150
        If Columns(lColNo).Hidden Then
            If blast Then
                '---1ColNo is Col 2 of 4 for Task
                bFound = True
                Exit For
            End If
        End If
        blast = Columns(lColNo).Hidden
    Next lColNo
    If bFound Then
        '---unhide Cols 1,2,4 of Task
        Columns(lColNo - 1).Resize(, 2).Hidden = False
        Columns(lColNo + 2).Hidden = False
    End If
End Sub
 
Upvote 0
Hi, I'm new to using VBA and hoping someone can show me the errors of my way.

I'm trying to create a function that will evaluate 2 cells (value1, value2) and whichever IS NOT BLANK it will do a vlookup to return an answer based on whichever cell (value1 or value2) is not empty. I wrote the following and keep getting Compile Error: Block If without End If and my Function line is highlighted in yellow.

Function LookupNotBlank(value1, value2)
If Not IsEmpty(value1.Value) Then​
LookupNotBlank = Application.worksheetfuction.vlookup(value1, Range("'Transition Proj'!$A$2:$B$10"), 2, 0)​
Else​
If Not IsEmpty(value2.Value) Then​
LookupNotBlank = Application.WorksheetFunction.vlookup(value2, Range("'Transition Proj'!$A$2:$B$10"), 2, 0)​
End If​
End Function
 
Last edited:
Upvote 0
You have 2 If statements and only one closing End If:
Code:
Function LookupNotBlank(value1, value2)
If Not IsEmpty(value1.Value) Then
   LookupNotBlank = Application.worksheetfuction.vlookup(value1, Range("'Transition Proj'!$A$2:$B$10"), 2, 0)
Else
   If Not IsEmpty(value2.Value) Then
      LookupNotBlank = Application.WorksheetFunction.vlookup(value2, Range("'Transition Proj'!$A$2:$B$10"), 2, 0)
   End If
End If
End Function
 
Upvote 0
am having a problem with my coding - end if without block if error.

Private Sub CommandButton1_Click()
Dim PANo As Integer, DateRaised As Date, BriefDescription As String, DivisionorArea As String, ToAction As String, DueDate As Date, DateCompleted As Date, Comments As String
Worksheets("sheet1").Select
PANo = Range("A2")
DateRaised = Range("A3")
BriefDescription = Range("A4")
DivisionorArea = Range("A5")
ToAction = Range("A6")
DueDate = Range("A7")
DateCompleted = Range("A8")
Comments = Range("A9")
Worksheets("sheet2").Select
Worksheets("sheet2").Range("A1").Select
If Worksheets("sheet2").Range("A1").Offset(1, 0) <> "" Then
Worksheets("sheet2").Range("A1").End(xlDown).Select
End If
Acitvecell.Offset(1, 0).Select
ActiveCell.Value = PANo
Acitvecell.Offset(0, 1).Select
ActiveCell.Value = DateRaised
Acitvecell.Offset(0, 0, 1).Select
ActiveCell.Value = BriefDescription
Acitvecell.Offset(0, 0, 0, 1).Select
ActiveCell.Value = DivisionorArea
Acitvecell.Offset(0, 0, 0, 0, 1).Select
ActiveCell.Value = ToAction
Acitvecell.Offset(0, 0, 0, 0, 0, 1).Select
ActiveCell.Value = DueDate
Acitvecell.Offset(0, 0, 0, 0, 0, 0, 0, 1).Select
ActiveCell.Value = DateCompleted
Acitvecell.Offset(0, 0, 0, 0, 0, 0, 0, 0, 1).Select
ActiveCell.Value = Comments
Acitvecell.Offset(0, 0, 0, 0, 0, 0, 0, 0, 0, 1).Select
Worksheets("sheet1").Select
Worksheets("sheet1").Range("A1").Select

End Sub
 
Upvote 0
There is no missing End If in that code, but you have misspelled ActiveCell on several occasions.
 
Upvote 0

Forum statistics

Threads
1,214,892
Messages
6,122,112
Members
449,066
Latest member
Andyg666

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