+ Reply to Thread
Results 1 to 7 of 7

VBA code to hide/unhide rows on 2 different sheets-HELP

  1. #1
    Forum Contributor
    Join Date
    05-12-2016
    Location
    spanaway
    MS-Off Ver
    2007
    Posts
    112

    VBA code to hide/unhide rows on 2 different sheets-HELP

    Hi all, I'm looking for a code to be able to hide different rows on 2 different sheets in a workbook. I have the code to hide/unhide on the first sheet and assigned to a button, but I cannot figure out how to expand the code to hide rows on the next sheet. basically I'm trying to hide seasonal categories when not needed. i have attached a sample workbook. any help figuring this out would be greatly appreciated.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: VBA code to hide/unhide rows on 2 different sheets-HELP

    Hi,

    You just need to specify what sheet you want to hide the rows for like this:

    Please Login or Register  to view this content.
    Regards,
    Stephen

    If you feel someone has helped you please thank them and click on the star on their post to add reputation.
    Please ensure that you use code tags where relevant, and mark solved threads as solved.
    Most of all please be respectful and understanding of others.

  3. #3
    Forum Contributor
    Join Date
    05-12-2016
    Location
    spanaway
    MS-Off Ver
    2007
    Posts
    112

    Re: VBA code to hide/unhide rows on 2 different sheets-HELP

    thanks for taking a look, but how to combine the 2 sheets together? I'm using < 'Sub sbHidingUnhideRows()
    'To Hide Rows 15 to 18> as part of my code, when I put your code in I get Run-time error '1004", Unable to set the Hidden property of the Range class, when I go to debug your code is highlighted. I'm not good with VBA at all, ha ha as you can tell.

  4. #4
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: VBA code to hide/unhide rows on 2 different sheets-HELP

    Hi,

    No problems. Your issue is that you need to unprotect the second sheet i.e.

    Please Login or Register  to view this content.
    In most cases you should try and reference your sheet rather than using "ActiveSheet" so then it doesn't matter what sheet you are in you can still run the code.
    I have amended the macros on the attached workbook using a With statement like this:

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

  5. #5
    Forum Contributor
    Join Date
    05-12-2016
    Location
    spanaway
    MS-Off Ver
    2007
    Posts
    112

    Re: VBA code to hide/unhide rows on 2 different sheets-HELP

    thanks a ton spitfireblue, works great. reputation added.

  6. #6
    Forum Contributor
    Join Date
    05-12-2016
    Location
    spanaway
    MS-Off Ver
    2007
    Posts
    112

    Re: VBA code to hide/unhide rows on 2 different sheets-HELP

    hi spitfire, thanks again for helping me with this way back, but i had to add some pages in this workbook and need to hide rows on other pages, but when i add to the code i get a Run-time error '9' subscript out of range. any ideas? i took the above code and added another with sheets line (just like line 2), when i go to debug it takes me to the third sheet prod variance. basically how can i manipulate this code for say 4 to 5 sheets? i dont have any variables, besides wanting to hide/hunide categories and the above code works great for just the 2 sheets listed above. each sheet does have some different row numbers that i put in.

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA code to hide/unhide rows on 2 different sheets-HELP

    The "Subscript out of range" means that you've got the names inexact - it's often a space in the name either in the code or in the sheet name
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

+ 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. Hide or unhide rows based on value across multiple sheets
    By Casper99 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-26-2016, 08:23 PM
  2. need code to hide/unhide rows
    By mariobross106 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-30-2015, 09:27 PM
  3. HIDE/UNHIDE Rows based on cell value in multiple sheets.
    By yatin1964 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2015, 12:29 AM
  4. [SOLVED] VBA to hide/unhide rows & columns on multiple sheets
    By Adam23 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-14-2015, 07:06 PM
  5. Hide and Unhide sheets based on Date [better code]
    By Deryl in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-30-2012, 09:22 AM
  6. Code to Hide and Unhide Rows
    By jcoulter in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-13-2012, 10:38 AM
  7. Hide/Unhide Rows VBA code Changes Help
    By Justinmih in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-12-2011, 04:24 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