![]() |
Hiding/Unhiding sheets and rows (An easy one for most of you....)
I have three sheets in my workbook and under certain circumstance I
need to hide/unhide and entire sheet, or just certain rows. Could some one give me an example on how to code a line to do this? Thanks! |
Hiding/Unhiding sheets and rows (An easy one for most of you....)
This hide's a sheet if OK is pressed:
Sub HideSheet() Dim hideit hideit = MsgBox("Press OK to hide", vbOKCancel, "Hide Test") If hideit = 1 Then Worksheets("Sheet1").Visible = False Else Worksheets("Sheet1").Visible = True End If End Sub This does the same with Column C Sub HideCol() Dim hideit hideit = MsgBox("Press OK to hide", vbOKCancel, "Hide Test") If hideit = 1 Then Columns("C:C").EntireColumn.Hidden = True Else Columns("C:C").EntireColumn.Hidden = False End If End Sub HTH Steve "Dean Goodmen" wrote in message ... I have three sheets in my workbook and under certain circumstance I need to hide/unhide and entire sheet, or just certain rows. Could some one give me an example on how to code a line to do this? Thanks! |
Hiding/Unhiding sheets and rows (An easy one for most of you....)
add this to the code for sheet1.make sure that you have a worksheet called
sheet2 Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$A$1" Then If Target.Value = 0 Then SheetHide "Sheet2" Else SheetUnhide "Sheet2" End If End If End Sub Sub SheetHide(sheetname As String) Worksheets(sheetname).Visible = False End Sub Sub SheetUnhide(sheetname As String) Worksheets(sheetname).Visible = True End Sub type 0 (zero) into A1 of sheet1 and sheet2 will be hidden. type anything else into A1 of sheet1 and sheet2 will be visible TIP: Use the macro-recorder & examine the code - it will be a big help. Usually the code will need to be tweaked to get it just so though. HTH Patrick Molloy Microsoft Excel MVP "Dean Goodmen" wrote: I have three sheets in my workbook and under certain circumstance I need to hide/unhide and entire sheet, or just certain rows. Could some one give me an example on how to code a line to do this? Thanks! |
Hiding/Unhiding sheets and rows (An easy one for most of you....)
That works great; however how would you hide multiple rows, or a range
of them? I tried Rows("2:5").Entirerow.Hidden = True, but it did not work... On Tue, 22 Feb 2005 18:30:44 +1100, "Steve" wrote: This hide's a sheet if OK is pressed: Sub HideSheet() Dim hideit hideit = MsgBox("Press OK to hide", vbOKCancel, "Hide Test") If hideit = 1 Then Worksheets("Sheet1").Visible = False Else Worksheets("Sheet1").Visible = True End If End Sub This does the same with Column C Sub HideCol() Dim hideit hideit = MsgBox("Press OK to hide", vbOKCancel, "Hide Test") If hideit = 1 Then Columns("C:C").EntireColumn.Hidden = True Else Columns("C:C").EntireColumn.Hidden = False End If End Sub HTH Steve "Dean Goodmen" wrote in message .. . I have three sheets in my workbook and under certain circumstance I need to hide/unhide and entire sheet, or just certain rows. Could some one give me an example on how to code a line to do this? Thanks! |
All times are GMT +1. The time now is 08:47 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com