+ Reply to Thread
Results 1 to 8 of 8

Macro to hide/unhide rows using more than one checkbox

  1. #1
    Registered User
    Join Date
    03-16-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    5

    Macro to hide/unhide rows using more than one checkbox

    Hello everyone,

    I hope you can help me editing the below macro.

    I have created a database in excel and for each column there is a header. Just below each header there is a checkbox which controls (shows/hides) rows depending on whether each cell at each specific column contains a character.

    For each checkbox I used the code below:

    Please Login or Register  to view this content.
    I used the above code for CheckBox1, CheckBox2.....CheckBox15 since I have 15 columns with headers.

    This code works fine as soon as one CheckBox is clicked and unclicked each time but when I click more than one CheckBox, the second Checkbox works on the resulting table from the already clicked first CheckBox.

    What I want to do is to create a macro which when CheckBox1 is clicked, it would show all the rows which cells contain the character "Y" and hides the rows with empty cells but at the same time when I click CheckBox2 (with CheckBox1 on), to show both results from CheckBox1 and CheckBox2. In the same principle, until CheckBox15.

    For the checkboxes I am using ActiveX Controls.

    I would be really grateful if you could help me on this!

    I hope I did not confuse you.

    Thanks a lot!
    Last edited by tsou; 03-27-2013 at 06:12 PM.

  2. #2
    Forum Contributor
    Join Date
    07-27-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Macro to hide/unhide rows using more than one checkbox

    Try the attached Excel file to see if it does what you need.
    Checking the boxes has a cumulative effect of hiding rows where
    the cell in the chosen column is blank. A command button is
    included to unhide all rows and uncheck the checkboxes.
    There is no code to support unchecking individual columns.
    Please Login or Register  to view this content.
    Be sure to add this code to a new module:
    Please Login or Register  to view this content.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    03-16-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Macro to hide/unhide rows using more than one checkbox

    Hello xLJer,

    Many thanks for your immediate and very detailed reply!

    The example you uploaded is really close to what I need. I have taken some screenshots (attached word file) using your example to show exactly the desired sequence of results to be shown each time a checkbox is clicked (I just edited the fields over the results for illustration purposes).

    I also tried to change a part of your code to the one below:
    Please Login or Register  to view this content.
    but unfortunately, it did not bring the desired result.

    Again, thanks a lot, I really appreciate you help on this!!!
    You've been already really helpful!
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    07-27-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Macro to hide/unhide rows using more than one checkbox

    This solution requires that previous selections be remembered
    as you progress from one checkbox to another.
    I have used column 16 to store a flag that tells the code
    that the row is to remain visible.

    I tested this code and the results match those in your images.
    Replace the For loop code:
    Please Login or Register  to view this content.
    and in the command button click event add:
    Please Login or Register  to view this content.
    Last edited by xLJer; 03-19-2013 at 02:42 PM.

  5. #5
    Registered User
    Join Date
    03-16-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Macro to hide/unhide rows using more than one checkbox

    Dear xLJer,

    I honestly have no words to say thank you for this! It was just what I needed! Spot on!

    I replaced the For loop code and it works perfectly!!!

    Thanks a lot!!!

  6. #6
    Registered User
    Join Date
    03-16-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Macro to hide/unhide rows using more than one checkbox

    Dear xLJer,

    The code works perfectly and I would like to move the whole part more to the right. The problem is that the code is already set for the rows below:

    Please Login or Register  to view this content.
    while I need to make it work for the rows X,Y,Z,AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,AK and AL.

    I tried the code below:

    Please Login or Register  to view this content.
    but it does not seem to work.

    Do you have any idea how I could overcome this problem?

    Thank you in advance.

  7. #7
    Forum Contributor
    Join Date
    07-27-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Macro to hide/unhide rows using more than one checkbox

    Replace the worksheet module code with the code below.
    A zero-based array is used to identify column numbers and
    letters for the box checked. Column #39 (AM) is used to track
    rows that are to remain visible.
    Please Login or Register  to view this content.
    Last edited by xLJer; 03-28-2013 at 01:40 PM. Reason: ckBoxName corrected for disabling under new scenario

  8. #8
    Registered User
    Join Date
    03-16-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Macro to hide/unhide rows using more than one checkbox

    xLJer,

    Your code works 100%!

    I received a lot of help from you! Many thanks to the Excel Forum site and to you xLJer!

    Best Regards

+ 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