Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Gwen H
 
Posts: n/a
Default Conditional Hide/Unhide Rows

I am working with a workbook that has one worksheet only. I want all rows
visible when the user opens the file. However, In cell B10, I have a
drop-down list I'm generating with data validation. The only values are YES
or NO, and YES is initially selected. If the user selects YES, then I want
the entire worksheet to remain visible. If the user selects NO, then I want
to hide rows 11 through 50, and display an error message entered in row 51.

Using previous posts, I've begun the code, but I know it's missing some
things.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$10" And Target.Value = "YES" Then
Range("B11").Select
ElseIf Target.Address = "$B$10" And Target.Value = "NO" Then
Rows("11:50").Select
Selection.EntireRow.Hidden = True
Range("A51").Select
End If
End Sub

Any help you can give me would be greatly appreciated.
  #2   Report Post  
John Mansfield
 
Posts: n/a
Default

Gwen, try . . .

Sub HideRows()
Dim Rng As Range
Set Rng = Sheets("Sheet1").Range("B10")
If Rng.Value = "YES" Then
Rows("11:50").EntireRow.Hidden = False
Range("B11").Select
ElseIf Rng.Value = "NO" Then
Rows("11:50").EntireRow.Hidden = True
Range("B51").Select
MsgBox "Your Error Message"
End If
End Sub

You can tie this macro to the drop-down list control. If using the
drop-down from the forms toolbar, right-click on the control and go to the
Assign Macro option.

----
Regards,
John Mansfield
http://www.pdbook.com


"Gwen H" wrote:

I am working with a workbook that has one worksheet only. I want all rows
visible when the user opens the file. However, In cell B10, I have a
drop-down list I'm generating with data validation. The only values are YES
or NO, and YES is initially selected. If the user selects YES, then I want
the entire worksheet to remain visible. If the user selects NO, then I want
to hide rows 11 through 50, and display an error message entered in row 51.

Using previous posts, I've begun the code, but I know it's missing some
things.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$10" And Target.Value = "YES" Then
Range("B11").Select
ElseIf Target.Address = "$B$10" And Target.Value = "NO" Then
Rows("11:50").Select
Selection.EntireRow.Hidden = True
Range("A51").Select
End If
End Sub

Any help you can give me would be greatly appreciated.

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
Count Rows with Conditional Format? Ken Excel Discussion (Misc queries) 3 March 24th 05 02:27 PM
Help using Conditional Formating of Entire Rows [email protected] Excel Worksheet Functions 4 February 16th 05 04:29 PM
Conditional Sum Rows Jhndeere Excel Worksheet Functions 0 February 15th 05 05:52 PM
Copy conditional formatting across multiple rows? Gil Excel Discussion (Misc queries) 1 January 11th 05 11:27 AM
How do I use conditional formatting for multiple rows? Jim Johnson Excel Worksheet Functions 1 October 30th 04 03:36 AM


All times are GMT +1. The time now is 08:33 PM.

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"