Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What's wrong with this if statement? Karen Excel Discussion (Misc queries) 5 July 19th 08 04:54 PM
IF Statement help please - again - got it wrong last time! Alan Davies Excel Worksheet Functions 2 May 12th 06 12:28 PM
wts wrong with this statement Jason Excel Worksheet Functions 2 February 24th 06 02:26 PM
What is wrong with this IF statement? need help. AC man Excel Discussion (Misc queries) 4 January 11th 06 03:29 PM
What's wrong with this SQL join statement???? Hexman Excel Programming 2 December 12th 05 04:49 AM


All times are GMT +1. The time now is 01:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"