Need to use a checking tab statement for several tabs and then receiving Else without If error

TkdKidSnake

Board Regular
Joined
Nov 27, 2012
Messages
245
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am trying to write a statement that checks if a tab is present and if it is perform certain tasks and if not move onto the next. Below is the code I have come up with however I keep getting the error message "Compile Error - Else Without If" also there is probably a better way of doing this.

Your help would be greatly appreciated.

See the code below:


Sub SortingBlocks()

Application.ScreenUpdating = False
Windows("002 - Downloaded Poan Report - RAW Data.xls").Activate

Dim sh As Worksheet, flg As Boolean
For Each sh In Worksheet

If sh.Name Like "GAL*" Then flg = True: Exit For
Next
If flg = True Then
Sheets("GAL").Select
Sheets("GAL").Move Before:=Sheets(1)
With ActiveWorkbook.Sheets("GAL").<wbr>Tab
.Color = 16711680
.TintAndShade = 0
'Call PageFormat
'Call Page1Ofxx
'Call RemoveUnwantedRows
Else

If sh.Name Like "SVC" Then flg = True: Exit For
Next
If flg = True Then
Sheets("SVC").Select
Sheets("SVC").Move Before:=Sheets(1)
With ActiveWorkbook.Sheets("SVC").<wbr>Tab
.Color = 16711680
.TintAndShade = 0
'Call PageFormat
'Call Page1Ofxx
'Call RemoveUnwantedRows
Else

If sh.Name Like "SLE*" Then flg = True: Exit For
Next
If flg = True Then
Sheets("SLE").Select
Sheets("SLE").Move Before:=Sheets(1)
With ActiveWorkbook.Sheets("SLE").<wbr>Tab
.Color = 16711680
.TintAndShade = 0
'Call PageFormat
'Call Page1Ofxx
'Call RemoveUnwantedRows
Else

If sh.Name Like "OLY*" Then flg = True: Exit For
Next
If flg = True Then
Sheets("OLY").Select
Sheets("OLY").Move Before:=Sheets(1)
With ActiveWorkbook.Sheets("OLY").<wbr>Tab
.Color = 16711680
.TintAndShade = 0
'Call PageFormat
'Call Page1Ofxx
'Call RemoveUnwantedRows
Else

If sh.Name Like "NEW*" Then flg = True: Exit For
Next
If flg = True Then
Sheets("NEW").Select
Sheets("NEW").Move Before:=Sheets(1)
With ActiveWorkbook.Sheets("NEW").<wbr>Tab
.Color = 16711680
.TintAndShade = 0
'Call PageFormat
'Call Page1Ofxx
'Call RemoveUnwantedRows
Else

If sh.Name Like "KBR*" Then flg = True: Exit For
Next
If flg = True Then
Sheets("KBR").Select
Sheets("KBR").Move Before:=Sheets(1)
With ActiveWorkbook.Sheets("KBR").<wbr>Tab
.Color = 16711680
.TintAndShade = 0
'Call PageFormat
'Call Page1Ofxx
'Call RemoveUnwantedRows
Else

If sh.Name Like "EUR*" Then flg = True: Exit For
Next
If flg = True Then
Sheets("EUR").Select
Sheets("EUR").Move Before:=Sheets(1)
With ActiveWorkbook.Sheets("EUR").<wbr>Tab
.Color = 16711680
.TintAndShade = 0
'Call PageFormat
'Call Page1Ofxx
'Call RemoveUnwantedRows
Else

If sh.Name Like "CDE" Then flg = True: Exit For
Next
If flg = True Then
Sheets("CDE").Select
Sheets("CDE").Move Before:=Sheets(1)
With ActiveWorkbook.Sheets("CDE").<wbr>Tab
.Color = 16711680
.TintAndShade = 0
'Call PageFormat
'Call Page1Ofxx
'Call RemoveUnwantedRows
Else
End If

End Sub



Thanks in advance!
 
Would this be easier?

Code:
Sub SortingBlocks()
 
Application.ScreenUpdating = False
 
Windows("002 - Downloaded Poan Report - RAW Data.xls").Activate
 
Dim s As Long, i As Long
 
s = Sheets.Count
 
For i = 1 To s
       If Sheets(i).Name Like "GAL*" Or Sheets(i).Name Like "SVC*" _
       Or Sheets(i).Name Like "SLE*" Or Sheets(i).Name Like "OLY*" _
       Or Sheets(i).Name Like "NEW*" Or Sheets(i).Name Like "KBR*" _
       Or Sheets(i).Name Like "EUR*" Or Sheets(i).Name Like "CDE*" Then
        Sheets(i).Move Before:=Sheets(1)
         
        'Do the rest of the things you want to do to the sheet
       End If
 
'Move to next sheet in loop
Next I
 
MsgBox "Done!"
 
End Sub

Many thanks Rallcorn this has worked a treat and will help in many of my other spreadsheets. Much Appreciate all of your help with this issue.
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,213,497
Messages
6,113,998
Members
448,539
Latest member
alex78

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