Expected Then or Go To when inputting Hard Return after OR

jbunn

New Member
Joined
Feb 6, 2013
Messages
30
Hi - I am receiving a an error when inputting an hard return after the OR (Expected Then or Go To). The error goes away if I remove the hard return and all OR's are on one line. Am I confinded to putting all OR's on one line?

Private Sub Worksheet_Change(ByVal Target As Range)
'Ensure the cells with Show/Hide are specified below
If Intersect(Target, Range("c410", "c21")) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Dim ws As Worksheet
'Master File Reports
If Target.Address = "$C$21" And Target = "Show Detail" Then
For Each ws In ActiveWorkbook.Worksheets
If ws.Name Like "MF-Client" Or ws.Name Like "361 - Client"
Or ws.Name Like "771-Client" Or ws.Name Like "MF-Employees" And ws.Visible = False Then
ws.Visible = True
End If
Next ws
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Use a line separator (space shift minus sign)

If ws.Name Like "MF-Client" Or ws.Name Like "361 - Client" _
Or ws.Name Like "771-Client" Or ws.Name Like "MF-Employees" And ws.Visible = False Then
 
Upvote 0
Use the line continuation character _.
Code:
        For Each ws In ActiveWorkbook.Worksheets
            If ws.Name Like "MF-Client" _
               Or ws.Name Like "361 - Client" _
               Or ws.Name Like "771-Client" _
               Or ws.Name Like "MF-Employees" _
               And ws.Visible = False Then
                ws.Visible = True
            End If
        Next ws
Or use Select Case.
Code:
 For Each ws In ActiveWorkbook.Worksheets
            Select Case ws.Name
                Case "MF-Client", "361 - Client", "771-Client", "MF-Employees"
                    If ws.Visible = False Then
                        ws.Visible = True
                    End If
                Case Else
                    ' do nothing
            End Select
 Next ws
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,521
Members
449,088
Latest member
RandomExceller01

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