+ Reply to Thread
Results 1 to 8 of 8

Hide Rows that are below a button (and be able to toggle)

  1. #1
    Registered User
    Join Date
    08-23-2016
    Location
    Toronto, Ontario
    MS-Off Ver
    2010
    Posts
    4

    Hide Rows that are below a button (and be able to toggle)

    Hi all,

    I am having trouble coming up with code that allows me to create buttons that toggles between hide/unhidden rows, relative to where the button is.

    Basically, i am trying to make it 2 buttons side by side, where button 1 will hide/unhide rows 2-6 below the button when clicked, button 2 will hide/unhide rows 7-11 below the button when clicked.

    Does anyone have experience with this sort of thing?

    Thanks

  2. #2
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,062

    Re: Hide Rows that are below a button (and be able to toggle)

    The code to go behind your Toggle buttons should be like this:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-23-2016
    Location
    Toronto, Ontario
    MS-Off Ver
    2010
    Posts
    4

    Re: Hide Rows that are below a button (and be able to toggle)

    Thanks for the help. It works great, but I was hoping to make the buttons a relative reference, so instead of hiding/unhiding rows 2-6, I want to hide the rows that are 2-6 rows below button... so if the button is on row 1, the toggle button would hide rows 2-6, but if the button is on row 11, it would hide rows 12-16, etc.

    From what I can tell the TopLeftCell property may be of help, but I don't know how to replace the range Rows("2:6") using that property.

  4. #4
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,062

    Re: Hide Rows that are below a button (and be able to toggle)

    Sounds to me that what you really want to use is the OFFSET property. Assuming Excel figures your button as the location of the activecell, this will work.
    Please Login or Register  to view this content.
    I ran across this code utilizing TopLeftCell to select the area under the button, but the article mentions that this code requires that all of your buttons have to be buttons made from the Forms Toolbar. .
    Please Login or Register  to view this content.
    I can't get it to work for me, but if you can you can change the macro above to 1) Select the region under the button, and 2) change "Activecell" to "Selection" and you'll be golden.
    Last edited by jomili; 08-24-2016 at 09:57 AM.

  5. #5
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,062

    Re: Hide Rows that are below a button (and be able to toggle)

    Okay, with some help from Nilem on another thread I think we can now get you squared away. In the code below, from HideUnderButtons we call SelectShape and pass it the number (1,2, etc, depending on which button you want as your base). SelectShape selects the topleftcell the button is touching, and the rest of our code does the hiding and unhiding.
    Please Login or Register  to view this content.
    Let me know if more help is needed.

  6. #6
    Registered User
    Join Date
    08-23-2016
    Location
    Toronto, Ontario
    MS-Off Ver
    2010
    Posts
    4

    Re: Hide Rows that are below a button (and be able to toggle)

    Hi, Thanks very much! Seems to get the job done so far.

    I am thinking I will need to expand this a little. Here is my understanding, I am still just learning so hopefully all this makes sense..

    Let's say I have 6 buttons lined up side by side, and each button hides different rows (button1 hides rows 2-6, button2 hides rows 8-12, button3 hides rows 14-18, button 4 hides rows 20-24, button5 hides rows 26-30, button65 hides rows 32-36)... and then I will repeat these 6 buttons several times throughout the sheet, as in the 6 buttons will do the same thing again starting on row 40... As of right now, all I have to do is use that code, make 6 copies (SubHideUnderButtons x 6) and just change the SelectShape (1) to SelectShape (2), (3), (4), (5), (6), but when I start again on row 40 for the 2nd batch of the 6 buttons I have copy the code and make 6 new Sub HideUnderButtons(7-13), and this will go on and on because I will end up with ~40 of these batches... this ends up being lots of code, not hard to do because I am just copy and pasting, but other people may want to use this in the future so I am trying to make this as simple as possible.

    so my question is, is there a way to make the button that is clicked the activeshape, such that button1, no matter where it is or how many copies I make of it, (row 1 or row 40), will always hide offset rows 2-6, whether it is row 2-6 or rows 42-46.

    Thanks again for your help so far!

  7. #7
    Registered User
    Join Date
    08-23-2016
    Location
    Toronto, Ontario
    MS-Off Ver
    2010
    Posts
    4

    Re: Hide Rows that are below a button (and be able to toggle)

    I think I got it working perfectly now. here is what I did.

    Please Login or Register  to view this content.
    and now I can just copy and paste my 6 buttons further down the sheet, and it will work for those too!

    thanks for all the help

  8. #8
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,062

    Re: Hide Rows that are below a button (and be able to toggle)

    Glad to know it helped. If this fixes your issue please don't forget to mark your thread "Solved".

+ 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. [SOLVED] New Question to Hide Rows with Toggle button and auto adjust for additional rows
    By The Phoenix in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-14-2015, 01:55 PM
  2. Need Toggle Button to hide/unhide rows based on cell value in non concurrent rows
    By The Phoenix in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-13-2015, 10:49 AM
  3. Show/Hide Rows & Columns Toggle Button
    By axegrynder in forum Excel General
    Replies: 2
    Last Post: 06-29-2015, 06:38 PM
  4. [SOLVED] Toggle Button to hide/unhide rows based on value
    By goomblar in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-03-2014, 07:35 AM
  5. VBA hide row based on pull down with button to toggle show/hide
    By myronr in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-12-2012, 06:07 PM
  6. [SOLVED] Toggle button to hide rows if empty and has no color
    By hi2chris in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-10-2012, 08:56 PM
  7. Using Toggle Button to hide/unhide rows that may change
    By jmpatrick in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-09-2011, 09:48 AM

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