Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default HIDE / UNHIDE sheets based on user answers

I would like to know how to hide / unhide sheets based on user answers in a
"main menu" sheet. Example: There are 2 sheets, "May" and "June", initially
hidden. In the "main menu" sheet (which is always visible), the user can type
either "show" or "hide" after each sheet name. After clicking on a "refresh"
button, the workbook refreshes showing or hiding the selected worksheets. I
am trying to use the following code, but it doesn't work. Hope you can help
me with this issue.

Range("H7").Activate
If Activecell.Value = "show" Then
Workbook.Sheets("May").visible = true
Else
Workbook.sheets("May").visible = false
End if
Range(ActiveCell.Offset(1,0)).Activate
If activecell.value = "show" then
Workbook.sheets("June").visible = true
Else
Workbook.sheets("June").visible = false
End if

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default HIDE / UNHIDE sheets based on user answers

Maybe this

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("H7,H8")) Is Nothing Then
If Target.Cells.Count 1 Or IsEmpty(Target) Then Exit Sub
Select Case UCase(Range("H7").Value)
Case Is = "SHOW"
Sheets("May").Visible = True
Case Is = "HIDE"
Sheets("May").Visible = xlVeryHidden
End Select

Select Case UCase(Range("H8").Value)
Case Is = "SHOW"
Sheets("JUNE").Visible = True
Case Is = "HIDE"
Sheets("JUNE").Visible = xlVeryHidden
End Select
End If
End Sub

Mike

"Jonatas Vasconcellos" wrote:

I would like to know how to hide / unhide sheets based on user answers in a
"main menu" sheet. Example: There are 2 sheets, "May" and "June", initially
hidden. In the "main menu" sheet (which is always visible), the user can type
either "show" or "hide" after each sheet name. After clicking on a "refresh"
button, the workbook refreshes showing or hiding the selected worksheets. I
am trying to use the following code, but it doesn't work. Hope you can help
me with this issue.

Range("H7").Activate
If Activecell.Value = "show" Then
Workbook.Sheets("May").visible = true
Else
Workbook.sheets("May").visible = false
End if
Range(ActiveCell.Offset(1,0)).Activate
If activecell.value = "show" then
Workbook.sheets("June").visible = true
Else
Workbook.sheets("June").visible = false
End if

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default HIDE / UNHIDE sheets based on user answers

Try this

If Range("H7").Value = "show" Then
For Each sht In Sheets
If sht.Name = "May" Then
sht.Visible = True
Exit For
End If
Next sht
Else
Workbook.Sheets("May").Visible = False
End If

If Range("H8").Value = "show" Then
For Each sht In Sheets
If sht.Name = "June" Then
sht.Visible = True
Exit For
End If
Next sht
Else
Workbook.Sheets("June").Visible = False
End If

"Bob Phillips" wrote:

With Range("H7")

If .Value = "show" Then
Workbook.Sheets("May").Visible = xlSheetVisible
Else
Workbook.Sheets("May").Visible = xlSheetHidden
End If

With .Range(.Offset(1, 0))

If .Value = "show" Then
Workbook.Sheets("June").Visible = xlSheetVisible
Else
Workbook.Sheets("June").Visible = xlSheetHidden
End If
End With
End With


--
__________________________________
HTH

Bob

"Jonatas Vasconcellos" <Jonatas
wrote in message ...
I would like to know how to hide / unhide sheets based on user answers in a
"main menu" sheet. Example: There are 2 sheets, "May" and "June",
initially
hidden. In the "main menu" sheet (which is always visible), the user can
type
either "show" or "hide" after each sheet name. After clicking on a
"refresh"
button, the workbook refreshes showing or hiding the selected worksheets.
I
am trying to use the following code, but it doesn't work. Hope you can
help
me with this issue.

Range("H7").Activate
If Activecell.Value = "show" Then
Workbook.Sheets("May").visible = true
Else
Workbook.sheets("May").visible = false
End if
Range(ActiveCell.Offset(1,0)).Activate
If activecell.value = "show" then
Workbook.sheets("June").visible = true
Else
Workbook.sheets("June").visible = false
End if




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default HIDE / UNHIDE sheets based on user answers

Thanks guys, but after trying each and every one of the alternatives, none of
them worked out. I am an Excel Programming begginer, so please understand.
Where exactly should I enter the code? How can I create a refresh button? I
am not sure that these codes work when, after unhiding some sheets, the user
wants to hide tham again just by typing hide. How can I do something like
that?

"Mike H" wrote:

Maybe this

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("H7,H8")) Is Nothing Then
If Target.Cells.Count 1 Or IsEmpty(Target) Then Exit Sub
Select Case UCase(Range("H7").Value)
Case Is = "SHOW"
Sheets("May").Visible = True
Case Is = "HIDE"
Sheets("May").Visible = xlVeryHidden
End Select

Select Case UCase(Range("H8").Value)
Case Is = "SHOW"
Sheets("JUNE").Visible = True
Case Is = "HIDE"
Sheets("JUNE").Visible = xlVeryHidden
End Select
End If
End Sub

Mike

"Jonatas Vasconcellos" wrote:

I would like to know how to hide / unhide sheets based on user answers in a
"main menu" sheet. Example: There are 2 sheets, "May" and "June", initially
hidden. In the "main menu" sheet (which is always visible), the user can type
either "show" or "hide" after each sheet name. After clicking on a "refresh"
button, the workbook refreshes showing or hiding the selected worksheets. I
am trying to use the following code, but it doesn't work. Hope you can help
me with this issue.

Range("H7").Activate
If Activecell.Value = "show" Then
Workbook.Sheets("May").visible = true
Else
Workbook.sheets("May").visible = false
End if
Range(ActiveCell.Offset(1,0)).Activate
If activecell.value = "show" then
Workbook.sheets("June").visible = true
Else
Workbook.sheets("June").visible = false
End if



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default HIDE / UNHIDE sheets based on user answers

The first thing is to get the worksheet change function working. I would add
a msgbox for testing purposes. There are three different type VBA Code
sheets in Excel

1) ThisWorkBooK
2) Sheets (one for every worksheet)
3) Modules

The Worksheet Change has to be in the VBA sheet for the sheet where you are
making the cahnge. the best way of geting there is to Right Click the Tab on
the bottom of the worksheet (normally sheet1) and select VIEW CODE. Then put
the routine in the VBA window.

Private Sub Worksheet_Change(ByVal Target As Range)

msgbox("worksheet Changing is working")
If Not Intersect(Target, Range("H7,H8")) Is Nothing Then
If Target.Cells.Count 1 Or IsEmpty(Target) Then Exit Sub
Select Case UCase(Range("H7").Value)
Case Is = "SHOW"
Sheets("May").Visible = True
Case Is = "HIDE"
Sheets("May").Visible = xlVeryHidden
End Select

Select Case UCase(Range("H8").Value)
Case Is = "SHOW"
Sheets("JUNE").Visible = True
Case Is = "HIDE"
Sheets("JUNE").Visible = xlVeryHidden
End Select
End If
End Sub


"Jonatas Vasconcellos" wrote:

Thanks guys, but after trying each and every one of the alternatives, none of
them worked out. I am an Excel Programming begginer, so please understand.
Where exactly should I enter the code? How can I create a refresh button? I
am not sure that these codes work when, after unhiding some sheets, the user
wants to hide tham again just by typing hide. How can I do something like
that?

"Mike H" wrote:

Maybe this

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("H7,H8")) Is Nothing Then
If Target.Cells.Count 1 Or IsEmpty(Target) Then Exit Sub
Select Case UCase(Range("H7").Value)
Case Is = "SHOW"
Sheets("May").Visible = True
Case Is = "HIDE"
Sheets("May").Visible = xlVeryHidden
End Select

Select Case UCase(Range("H8").Value)
Case Is = "SHOW"
Sheets("JUNE").Visible = True
Case Is = "HIDE"
Sheets("JUNE").Visible = xlVeryHidden
End Select
End If
End Sub

Mike

"Jonatas Vasconcellos" wrote:

I would like to know how to hide / unhide sheets based on user answers in a
"main menu" sheet. Example: There are 2 sheets, "May" and "June", initially
hidden. In the "main menu" sheet (which is always visible), the user can type
either "show" or "hide" after each sheet name. After clicking on a "refresh"
button, the workbook refreshes showing or hiding the selected worksheets. I
am trying to use the following code, but it doesn't work. Hope you can help
me with this issue.

Range("H7").Activate
If Activecell.Value = "show" Then
Workbook.Sheets("May").visible = true
Else
Workbook.sheets("May").visible = false
End if
Range(ActiveCell.Offset(1,0)).Activate
If activecell.value = "show" then
Workbook.sheets("June").visible = true
Else
Workbook.sheets("June").visible = 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
Hide or unhide sheets based on cell billinr Excel Discussion (Misc queries) 2 July 13th 07 07:42 PM
Hide/Unhide Sheets Runner77[_4_] Excel Programming 2 January 16th 06 09:19 AM
Hide/Unhide sheets ali Excel Programming 1 January 30th 04 10:06 PM
Hide/Unhide sheets [email protected] Excel Programming 4 January 5th 04 03:32 AM
Password to hide and unhide sheets Patrick Molloy Excel Programming 0 July 23rd 03 04:04 PM


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