#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Hide Rows

I am trying to get this code to work where if a user enters an X in a
range of cells a corresponding group of rows is hidden further down in
the worksheet and I don't know what I am doing wrong.

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("B5") = "X" Then
Range("B9:B15").EntireRow.Hidden = True
Else
Range("B9:B15").EntireRow.Hidden = False
End If

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Hide Rows

Try this

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$5" Then
If Target = "X" Then
Range("B9:B15").EntireRow.Hidden = True
Else
Range("B9:B15").EntireRow.Hidden = False
End If
End If
End Sub



On 18 Sep, 12:40, newguy wrote:
I am trying to get this code to work where if a user enters an X in a
range of cells a corresponding group of rows is hidden further down in
the worksheet and I don't know what I am doing wrong.

Private Sub Worksheet_Change(ByVal Target As Range)
*If Range("B5") = "X" Then
* * Range("B9:B15").EntireRow.Hidden = True
* *Else
* * Range("B9:B15").EntireRow.Hidden = False
*End If

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Hide Rows

The code works fine so there are only threee reasons it is not working for your

1) You are typing a small x instead of a Capital x
2) The Macro is on the wrong worksheet. the code has to be on the VBA sheet
that coorresponds to the worksheet you are working with. The macro can't be
in a module sheet or THISWORKBOOK.
3) Macros or event are disabled Try running the code to enable events

Sub test()

Application.EnableEvents = True

End Sub


Also make sure none event macros are working. You workbook may bed in the
wrong security mode or if you have Medium security level then you may of
forgotten to enable macros when you opened the workbook.

"newguy" wrote:

I am trying to get this code to work where if a user enters an X in a
range of cells a corresponding group of rows is hidden further down in
the worksheet and I don't know what I am doing wrong.

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("B5") = "X" Then
Range("B9:B15").EntireRow.Hidden = True
Else
Range("B9:B15").EntireRow.Hidden = False
End If

End Sub

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
Macro code to hide rows and not calculate hidden rows bradmcq Excel Discussion (Misc queries) 0 September 1st 09 12:38 AM
Enabling option „Format rows“ to hide/unhide rows using VBA-code? ran58 Excel Discussion (Misc queries) 0 July 28th 09 03:46 PM
Code for Excel 2007 to hide rows based on sum of several rows not ina range Joe Gardill Excel Programming 2 August 29th 08 03:53 PM
Specify which rows to NOT hide, and have excel hide the rest Mo2 Excel Programming 0 April 25th 07 03:44 AM
Hide Rows - copy and paste only rows that show Access101 Excel Worksheet Functions 3 March 1st 06 12:39 AM


All times are GMT +1. The time now is 11:45 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"