ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If Then statement in macro gone wrong (https://www.excelbanter.com/excel-programming/360395-if-then-statement-macro-gone-wrong.html)

ellmcg

If Then statement in macro gone wrong
 
Can anyone tell me whats wrong with the below? It keeps returning the
message "Compile Error: Else without If", when it gets to 'ActiveCell', on
the 2nd line...

If ActiveCell = "" Then Selection.Rows.Hidden = True
Else: If ActiveCell = "Blah Blah Blah" Then Selection.Rows.RowHeight =
25.5
Else: Selection.Rows.AutoFit
End If

JMB

If Then statement in macro gone wrong
 
Since VBA allows you to put If/Then on the same line, the Else is being
treated as its own statement.

If ActiveCell = "" Then
Selection.Rows.Hidden = True
Elseif ActiveCell = "Blah Blah Blah" Then
Selection.Rows.RowHeight = 25.5
Else: Selection.Rows.AutoFit
End If

"ellmcg" wrote:

Can anyone tell me whats wrong with the below? It keeps returning the
message "Compile Error: Else without If", when it gets to 'ActiveCell', on
the 2nd line...

If ActiveCell = "" Then Selection.Rows.Hidden = True
Else: If ActiveCell = "Blah Blah Blah" Then Selection.Rows.RowHeight =
25.5
Else: Selection.Rows.AutoFit
End If


ellmcg

If Then statement in macro gone wrong
 
Thanks! I'd tried tweaking the layout in so many ways, but hadn't been able
to get the right one...


"JMB" wrote:

Since VBA allows you to put If/Then on the same line, the Else is being
treated as its own statement.

If ActiveCell = "" Then
Selection.Rows.Hidden = True
Elseif ActiveCell = "Blah Blah Blah" Then
Selection.Rows.RowHeight = 25.5
Else: Selection.Rows.AutoFit
End If

"ellmcg" wrote:

Can anyone tell me whats wrong with the below? It keeps returning the
message "Compile Error: Else without If", when it gets to 'ActiveCell', on
the 2nd line...

If ActiveCell = "" Then Selection.Rows.Hidden = True
Else: If ActiveCell = "Blah Blah Blah" Then Selection.Rows.RowHeight =
25.5
Else: Selection.Rows.AutoFit
End If



All times are GMT +1. The time now is 10:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com