thk12205
03-07-2018, 09:37 AM
Version: 2013 Professional Plus
I am trying to run a basic If, ElseIf, End If script, however the If and Else If seem to not be connected to eachother.
The error I run into is “Compile Error: Else without If”. If I delete the script underneath the IF statement, the error disappears.
Is there something in the body of the If statement that is stopping If and ElseIf from connecting?
Sub MoveButtons()
Application.ScreenUpdating = False
Dim rng As Range
If Columns("H").Hidden = True And Columns("K").Hidden = True And Columns("O").Hidden = True Then ActiveSheet.Range("A1") = 1
Set rng = ActiveSheet.Range("P4")
With ActiveSheet.Shapes("Button 3")
.Top = rng.Top
.Left = rng.Left
.IncrementLeft 0
Set rng = ActiveSheet.Range("P4")
With ActiveSheet.Shapes("Button 7")
.Top = rng.Top
.Left = rng.Left
.IncrementLeft 30
Set rng = ActiveSheet.Range("P4")
With ActiveSheet.Shapes("Button 9")
.Top = rng.Top
.Left = rng.Left
.IncrementLeft 60
End With
ElseIf Columns("H").Hidden = False And Columns("K").Hidden = True And Columns("O").Hidden = True Then
ActiveSheet.Range("A1") = 2
Set rng = ActiveSheet.Range("J4")
With ActiveSheet.Shapes("Button 2")
.Top = rng.Top
.Right = rng.Right
.IncrementLeft
Set rng = ActiveSheet.Range("P4")
With ActiveSheet.Shapes("Button 7")
.Top = rng.Top
.Left = rng.Left
.IncrementLeft
Set rng = ActiveSheet.Range("P4")
With ActiveSheet.Shapes("Button 9")
.Top = rng.Top
.Left = rng.Left
.IncrementLeft 30
End With
Else
MsgBox "Error"
End If
Application.ScreenUpdating = True
I am trying to run a basic If, ElseIf, End If script, however the If and Else If seem to not be connected to eachother.
The error I run into is “Compile Error: Else without If”. If I delete the script underneath the IF statement, the error disappears.
Is there something in the body of the If statement that is stopping If and ElseIf from connecting?
Sub MoveButtons()
Application.ScreenUpdating = False
Dim rng As Range
If Columns("H").Hidden = True And Columns("K").Hidden = True And Columns("O").Hidden = True Then ActiveSheet.Range("A1") = 1
Set rng = ActiveSheet.Range("P4")
With ActiveSheet.Shapes("Button 3")
.Top = rng.Top
.Left = rng.Left
.IncrementLeft 0
Set rng = ActiveSheet.Range("P4")
With ActiveSheet.Shapes("Button 7")
.Top = rng.Top
.Left = rng.Left
.IncrementLeft 30
Set rng = ActiveSheet.Range("P4")
With ActiveSheet.Shapes("Button 9")
.Top = rng.Top
.Left = rng.Left
.IncrementLeft 60
End With
ElseIf Columns("H").Hidden = False And Columns("K").Hidden = True And Columns("O").Hidden = True Then
ActiveSheet.Range("A1") = 2
Set rng = ActiveSheet.Range("J4")
With ActiveSheet.Shapes("Button 2")
.Top = rng.Top
.Right = rng.Right
.IncrementLeft
Set rng = ActiveSheet.Range("P4")
With ActiveSheet.Shapes("Button 7")
.Top = rng.Top
.Left = rng.Left
.IncrementLeft
Set rng = ActiveSheet.Range("P4")
With ActiveSheet.Shapes("Button 9")
.Top = rng.Top
.Left = rng.Left
.IncrementLeft 30
End With
Else
MsgBox "Error"
End If
Application.ScreenUpdating = True