Receiving an End If without block If error

jbunn

New Member
Joined
Feb 6, 2013
Messages
30
Hi - Can anyone clarify why I am recieving the "End if without block if" error . See code below. Essentially, based on a cell value trigger, I am trying to change a worksheet name.

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A1")) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Dim ws As Worksheet
If Target.Address = "$A$1" And Target = "Interface" Then
For Each ws In ActiveWorkbook.Worksheets
If ws.Name = "Co. Desc Category - Pick List" Then ws.Name = "co_desc_category_code_interface"
End If
Next ws
ElseIf Target.Address = "$A$1" And Target = "Client" Then
For Each ws In ActiveWorkbook.Worksheets
If ws.Name = "co_desc_category_code_interface" Then ws.Name = "Co. Desc Category - Pick List"
End If
Next ws
End If
 
A couple of your IF's are NOT block IF's..They are one liners..

When the The Action If True is written on the Same line as the If Expression.
This syntax does not have an End If
Rich (BB code):
If Intersect(Target, Range("A1")) Is Nothing Then Exit Sub '<- Action if true written on same line, No End If used.


You only use End if when the Action if true is written on new line like this one
Rich (BB code):
If Target.Address = "$A$1" And Target = "Interface" Then
        For Each ws In ActiveWorkbook.Worksheets '<-Action if True is written on a new line, End If is required.
End If
 
Upvote 0

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