+ Reply to Thread
Results 1 to 2 of 2

Hiding and unhiding worksheets based on a cell value from another worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    04-24-2013
    Location
    Inola, Ok
    MS-Off Ver
    Excel 2007
    Posts
    6

    Hiding and unhiding worksheets based on a cell value from another worksheet

    I am trying to set up an excel spreadsheet so that based on a value in a cell it will unhide a given number of worksheets. Example: I have 6 worksheets named Section 1, Section2, Section 3, etc. On the “Input” worksheet I have a cell where I want to enter a value between 1 & 6 and based on that value the given number of worksheets will unhide. If I enter the value of “2” then I want worksheets “Section 1” & “Section 2” to be unhidden, a value of 3 would unhide “Section 1”, “Section 2” & “Section 3”. I want to accomplish this using VBA.

  2. #2
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: Hiding and unhiding worksheets based on a cell value from another worksheet

    HI,

    A suggestion is to use a worksheet Change event that will trigger a code to unhide the work sheets.

    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Mynr as Long
    dim i as long
        If Target.Address = "$A$1" Then''change to the location in the Input sheet
          Mynr = Target.value''' added
          ''' set loop to unhide the sheets ''
           For i = 1 to Mynr
             ''' place code here to unhide the sheet
                 Sheets("Section" & i).Visible = False
           next i
       end if
     end sub
    Not tested but you get the ideal.
    Last edited by Charles; 06-05-2013 at 01:28 PM. Reason: corrected code for sheet again
    Charles

    There are other ways to do this, this is but 1 !
    Be Sure you thank those who helped.
    IF YOU'RE SATISFIED BY ANY MEMBERS RESPONSE TO YOUR ISSUE PLEASE USE THE STAR ICON AT THE BOTTOM LEFT OF THE POST UNDER THEIR NAME.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1