+ Reply to Thread
Results 1 to 12 of 12

Hiding and Unhiding two sets of worksheets

  1. #1
    Forum Contributor
    Join Date
    11-13-2007
    Location
    Petersfield, Hampshire, UK
    MS-Off Ver
    MS Office for Mac ver 16
    Posts
    135

    Hiding and Unhiding two sets of worksheets

    My Workbook has 72 worksheets split into two. The first 36 include all the data, but the second 36 have one element removed.
    I am very grateful to RoyUK and others who have steered me towards some code that allows me to hide and unhide the first 36 sheets exactly as I want, but when I add the second 36 the code comes up with an error saying the Procedure is too large.
    I did want to split the code into two parts activated by two validated drop down menus, but this did not work either.

    If I have two drop down menus at D8 and G8 is it possible to have two separate codes as follows

    Please Login or Register  to view this content.
    The code is OK when I have 36 Worksheets and link this code to one drop down menu. When there are 72 Worksheets it fails. There must be a way to shorten the commands but
    Please Login or Register  to view this content.
    Does not work whereas
    Please Login or Register  to view this content.
    does!

    This question is linked to my previous post :-

    Can I attach a macro to a drop down list selection

    Regards

    Geoff
    Last edited by Glio; 10-14-2008 at 03:09 PM.
    Geoff Culbertson
    Petersfield, UK

  2. #2
    Forum Contributor
    Join Date
    06-14-2008
    Posts
    153
    Hi,

    If you can split your code in two separate macros, then you can try this:

    In the ListBox_Click event or ComboBox_Change event (depending on which one you are using as a dropdown), check for the Text property and run the relevant macro accordingly. Here is a sample code:
    Please Login or Register  to view this content.
    Regards.
    Welcome to: http://www.exceldigest.com/myblog/
    "Excel help for the rest of us"

  3. #3
    Registered User
    Join Date
    10-07-2008
    Location
    Wessex
    Posts
    55
    How about something like this

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    11-13-2007
    Location
    Petersfield, Hampshire, UK
    MS-Off Ver
    MS Office for Mac ver 16
    Posts
    135
    Thanks very much for the responses from SE1429 and Martesoft. I was having trouble with a ComboBox so tried MarteSoft's idea and understanding it almost fully implemented it successfully, until I came across the inbuilt limit of 60 arguments for a procedure. Unfortunately I need 72.

    Microsoft Help tells me that I can do this with an array "You can also pass multiple arguments by placing them in an array"

    My working code is as follows with 36 Worksheets, but I need to add another set of 36 Worksheets in exactly the same format as the first 36.

    How can I implement an array to get round the 60 argument limit?

    Thanks again for all the ideas.


    Please Login or Register  to view this content.

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,468
    I would go with this approach.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  6. #6
    Forum Contributor
    Join Date
    11-13-2007
    Location
    Petersfield, Hampshire, UK
    MS-Off Ver
    MS Office for Mac ver 16
    Posts
    135
    Andy,

    Thank you so much, that is so much simpler!!

    Your code tackles the first 36 of my worksheets, but the next 36 are Main1 to Main8, Main1 being 1 worksheet, Main2 being 2 worksheets etc.

    I would also like to have a Case showing all the Sheets, a Case showing all the Mains and a Case hiding all the worksheets.

    It just amazes me how many different ways of doing the same thing there are!

    Thanks again

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,468
    Pass the Sheet/Main information as another argument.
    And add condition to test for Index of zero and use that to unhide all appropriate sheets.

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    11-13-2007
    Location
    Petersfield, Hampshire, UK
    MS-Off Ver
    MS Office for Mac ver 16
    Posts
    135
    Andy,

    Thanks a lot, I'm almost there!! I had to change the last Next to an End If.

    My worksheets are now named 1-Sheet1_F through to 8-Sheet8_F and 1-Sheet1_M to 8-Sheet8_M. As a result I have changed the order of the lngIndex and Names in your code.

    I can now select any of the M or F drop down menu items and it will display them but it does not hide the F or M sheets previously selected.

    If I manually hide all worksheets and then select All-Ms or All-Fs it works as expected.
    The problem seems to be in the second Else argument in SheetVisibility Sub. I have tried changing this part but have only managed to make it worse! Can you see what is wrong?

    Please Login or Register  to view this content.

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,468
    This revision should take care of the all _F or _M sheets.

    Please Login or Register  to view this content.
    With this change to the worksheet event
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    11-13-2007
    Location
    Petersfield, Hampshire, UK
    MS-Off Ver
    MS Office for Mac ver 16
    Posts
    135
    Andy,

    Your code is excellent and I mostly understand it, however I would never have got anywhere near this without yours and other peoples help.

    In the attached workbook, including your code, you will see that from the Control worksheet if you select All-F, all the worksheets ending with _F are revealed and the same with All-M, all worksheets ending _M are revealed. If having selected All-M you then select 1-F, the only worksheets that should be visible is 1-Sheet_F, but all the worksheets ending _M are still visible.

    I tried to include Case "None" by combining your code for All-F and All-M but could not get it to run. This is one bit of the code I do not understand very well, but think it is in the first 2 For in SheetVisibility!

    Would it be easier to re-name each of the worksheets so that they are F_1-Sheet1 to F_8-Sheet8 etc?

    Regards

    Geoff
    Last edited by Glio; 10-14-2008 at 03:10 PM.

  11. #11
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,468
    You need to add another test, this time for the value -1 which will be used to mean hide both Name and Othername sheets.
    Also you will need to pass both _F and _M in order to hide all sheets when picking a specific value.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    11-13-2007
    Location
    Petersfield, Hampshire, UK
    MS-Off Ver
    MS Office for Mac ver 16
    Posts
    135
    Andy,

    That is magnificent!!

    Just in case anyone else has been following this thread, attached is the final complete working workbook.

    Yet again ExcelForum.com answers all the questions.

    Best Regards

    Geoff
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Unhiding and Hiding Worksheets based on a range of values
    By menor59 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-03-2008, 12:33 AM
  2. Button For Hiding & Unhiding Rows
    By LAWDAWG in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2008, 04:37 PM
  3. Hiding and unhiding rows - two scenarios
    By EdMac in forum Excel General
    Replies: 6
    Last Post: 02-08-2007, 02:16 PM
  4. Hiding and unhiding column automaticaly when a cell value changes
    By titovalle in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-20-2006, 09:08 PM
  5. Hiding or unhiding a picture
    By krabople in forum Excel General
    Replies: 3
    Last Post: 11-08-2006, 01:03 PM

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