TkdKidSnake
Board Regular
- Joined
- Nov 27, 2012
- Messages
- 245
- Office Version
- 365
- Platform
- 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!
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!