+ Reply to Thread
Results 1 to 16 of 16

hiding / showing columns...

  1. #1
    Registered User
    Join Date
    07-11-2006
    Posts
    17

    hiding / showing columns...

    I've searched online and spent hours trying to make this work, and right now I'm feeling very stupid... can someone please help?

    It should be pretty straightforward really, but somehow I keep getting this stupid "Subscript out of range" error.

    Here's what I'm trying to do -

    There's a sheet called "Main" and 38 other sheets that shows the data (these 38 sheets all have the exact same structure/layout). Let's say these 38 sheets are called "country1", "country2", .... "country38".

    Based on user input in cell J10 in "Main", I want to show only the relevant columns in all of the 38 country sheets. Specifically,

    If J10 in sheet "Main" = "Option 1", hide all columns in all 38 sheets except columns A to W.

    If J10 in sheet "Main" = "Option 2", hide all columns in all 38 sheets except columns Y to AU.

    If J10 in sheet "Main" = "Option 3", hide all columns in all 38 sheets except columns AW to BS.

    If J10 in sheet "Main" = "Option 4", hide all columns in all 38 sheets except columns BV to CQ.

    If J10 sheet "Main = "ShowAll", show all columns in all 38 sheets....




    Cell J10 in "Main" will be a drop down bar with the 5 choices.....


    Thanks for your help in advance....

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Post the code you're using ...

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try setting up Custom Views. Then use a WorkSheet_Change event to hide/unhide the views based on the selection in J10. The basic code for this can be recorded.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Note: Your requests will hide J10 in Main sheet also so you will lose the control.

    Right click sheet tab > select View code > paste in the below

    Please Login or Register  to view this content.
    VBA Noob
    Last edited by VBA Noob; 07-07-2008 at 02:41 PM.
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  5. #5
    Registered User
    Join Date
    07-11-2006
    Posts
    17
    VBA Noob...

    Oh wow, that looks so much more elegant than my dummy approach (that didn't work). I basically did a record macro and repeated the code 38 times changing the sheet names.

    One thing though, since I have other sheets in the file (calculation worksheetsheets) other than the 38 output sheets (called "country1, country2, etc...), is it possible to ammend your code so that the code only operates on the 38 country sheets instead of every sheet in the file?

    Many thanks again.

  6. #6
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Maybe

    Please Login or Register  to view this content.
    VBA Noob

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Typo, Noob:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    07-11-2006
    Posts
    17
    OK, so I copied your code and changed some of the names to match the actual sheet names.... When my cell J10 is changed, the hiding of columns should happen automatically, right? Well, nothing is happening... I'm wondering what I'm not doing right.....

    By the way, the country output sheets are actually called "AMR Sales", "US Sales", "BR Sales", "MX Sales", "EUR Sales", "DE Sales", etc. etc....

    Please Login or Register  to view this content.
    Last edited by LSB M; 07-07-2008 at 04:10 PM.

  9. #9
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Please read forum rules and then wrap the code

    VBA Noob

  10. #10
    Registered User
    Join Date
    07-11-2006
    Posts
    17
    Quote Originally Posted by VBA Noob
    Please read forum rules and then wrap the code

    VBA Noob

    sorry for being such a noob... I actually changed it almost immedaitely after posting but I guess you beat me to it...

  11. #11
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Thanks

    You could Try

    Please Login or Register  to view this content.
    VBA Noob

  12. #12
    Registered User
    Join Date
    07-11-2006
    Posts
    17
    I cut and pasted your above (word for word), and I am getting a runtime error code "1004", "Unable to set the Hidden property of the Range class".


    Sorry for being such a pain... I really appreciate your help.

  13. #13
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Unhide all columns on all sheets first and then test it

    VBA Noob

  14. #14
    Registered User
    Join Date
    07-11-2006
    Posts
    17
    Quote Originally Posted by VBA Noob
    Unhide all columns on all sheets first and then test it

    VBA Noob
    Tried that, still getting the same error...


  15. #15
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Mine seems to work. Post a sample file without data

    VBA Noob

  16. #16
    Registered User
    Join Date
    07-11-2006
    Posts
    17
    Quote Originally Posted by VBA Noob
    Mine seems to work. Post a sample file without data

    VBA Noob
    I tried to reduce the file size by deleting all data, and eventually deleting most of the 50 sheets. Even with 3 sheets remaining and zipped, I am at 178KB which means I cannot upload the file... is there anyway I can email it or something?

+ 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