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?
 
Code:
Sub Age_Gender_AgeGroup()


Dim Gender As String


Gender = Worksheets("Assignment 2").Range("C2").Value


Dim Age As Integer


Age = Worksheets("Assignment 2").Range("c3").Value
If Age <= 0 Or Age > 165 Then
 MsgBox "Age is invalid. Age Should be Greater than 0 and Less than 166"
 Else
 
Dim AgeGroup As String


If Age <= 2 And Age > 0 Then
AgeGroup = "Infant"
ElseIf Age <= 10 And Age > 2 Then
AgeGroup = " Toddler"
ElseIf Age <= 17 And Age > 10 Then
AgeGroup = " Teenager"
ElseIf Age <= 30 And Age > 17 Then
AgeGroup = "Adult"
ElseIf Age <= 55 And Age > 30 Then
AgeGroup = "MID Adult"
ElseIf Age > 55 Then
AgeGroup = "Senior"
MsgBox "You Are: " & Gender & Chr(10) & "Your age is: " & Age & " " & "Your Age Group is " & AgeGroup
End If
End Sub


I am getting a Compile error: "Black If without End If". Can someone please help me on this.
 
Last edited by a moderator:
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Welcome to the forum.

The first If clause has no corresponding End If. Add one before the End Sub line.
 
Upvote 0

Forum statistics

Threads
1,215,430
Messages
6,124,846
Members
449,194
Latest member
HellScout

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