Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Hiding Rows and Columns

I have two check boxes.

Depending on which is checked, I have a cell that reads either 1 or 2.

Right now, I have conditional formatting set up to "Black Out" sections
of the workbook, depending on which box is checked.

Is there any way to just hide these rows or columns?

The blacked out thing looks kinda tacky.

Example: Cell=1, then hide rows 2,3,and 4. Cell=2, then hide rows 8, 9,
and 10.

Something like that.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Hiding Rows and Columns

Smarty,
Try something like this, go to VBE, from the Microsoft Excel Objects
under your Workbook, select the sheet you want to work with, then paste
in this code:

Private Sub Worksheet_Change(ByVal Target As Range)

If Left(Target.Address, 2) = "$A" Then
If Target.Value = "1" Then
Rows("2:4").EntireRow.Hidden = True
ElseIf Target.Value = "2" Then
Rows("8:10").EntireRow.Hidden = True
ElseIf Target.Value = "" Then
Cells.Select
Selection.EntireRow.Hidden = False
End If
End If
End Sub

Let me know if this is what you were looking for.
Andrew Armstrong

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Hiding Rows and Columns

How are you blacking out, conditional formatting?

You could try event code, like so


Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H10" '<=== change to suit
Const COLUMNS_1 As String = "M:O" '<=== change to suit
Const COLUMNS_2 As String = "T:Z" '<=== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Me.Columns(COLUMNS_1).Hidden = .Value = 1
Me.Columns(COLUMNS_2).Hidden = .Value = 2
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"SmartyPants" wrote in message
ups.com...
I have two check boxes.

Depending on which is checked, I have a cell that reads either 1 or 2.

Right now, I have conditional formatting set up to "Black Out" sections
of the workbook, depending on which box is checked.

Is there any way to just hide these rows or columns?

The blacked out thing looks kinda tacky.

Example: Cell=1, then hide rows 2,3,and 4. Cell=2, then hide rows 8, 9,
and 10.

Something like that.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Hiding Rows and Columns

Oops, I see you said CF. Doh!

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"SmartyPants" wrote in message
ups.com...
I have two check boxes.

Depending on which is checked, I have a cell that reads either 1 or 2.

Right now, I have conditional formatting set up to "Black Out" sections
of the workbook, depending on which box is checked.

Is there any way to just hide these rows or columns?

The blacked out thing looks kinda tacky.

Example: Cell=1, then hide rows 2,3,and 4. Cell=2, then hide rows 8, 9,
and 10.

Something like that.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Hiding Rows and Columns


I did it like this


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim SHIFT As Variant

SHIFT = Sheets("Production").Range("DN28").Value

If SHIFT = 1 Then

Sheets("Production").Rows("37:38").EntireRow.Hidde n = True
Sheets("Production").Rows("34:36").EntireRow.Hidde n = False



ElseIf SHIFT = 2 Then

Sheets("Production").Rows("34:36").EntireRow.Hidde n = True
Sheets("Production").Rows("37:38").EntireRow.Hidde n = False


End If



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Hiding Rows and Columns

Surely DN38 is Target, so why not just check target?

and no need to set entirerow when addressing rows.,

And you can do the hide/unhide in one statement as I showed

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$DN$38" Then
Me.Rows("37:38").Hidden = Target.Value = 1
Me.Rows("34:36").Hidden = Target.Value = 2
End If
End Sub



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"SmartyPants" wrote in message
ps.com...

I did it like this


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim SHIFT As Variant

SHIFT = Sheets("Production").Range("DN28").Value

If SHIFT = 1 Then

Sheets("Production").Rows("37:38").EntireRow.Hidde n = True
Sheets("Production").Rows("34:36").EntireRow.Hidde n = False



ElseIf SHIFT = 2 Then

Sheets("Production").Rows("34:36").EntireRow.Hidde n = True
Sheets("Production").Rows("37:38").EntireRow.Hidde n = False


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
Hiding rows and columns in XL 07 mlenard New Users to Excel 3 August 31st 09 05:42 PM
hiding columns with merged rows Cormac Excel Discussion (Misc queries) 3 June 5th 08 01:29 PM
Hiding rows and columns in a procedure Doo0592 Excel Programming 3 September 5th 06 04:29 PM
Hiding rows and columns matelot Excel Programming 6 December 14th 05 06:56 PM
Hiding of rows and columns srinivasan Excel Discussion (Misc queries) 1 July 21st 05 08:59 AM


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