+ Reply to Thread
Results 1 to 39 of 39

Hide checkbox when rows are hidden

  1. #1
    Registered User
    Join Date
    09-12-2012
    Location
    KC
    MS-Off Ver
    Excel 2010
    Posts
    24

    Hide checkbox when rows are hidden

    I am creating a checklist of items where each applicable item needs to be checked off. Based on the "Instructions" tab, I have created a macro that automatically hides certain rows of the checklist (on the "Questionnaire" tab) based on certain criteria. Here is the code for that macro:

    PHP Code: 
    Private Sub Worksheet_Change(ByVal Target As Range'on the worksheet change
    Dim LR As String, c As Range    '
    declare variables

    Select 
    Case Target.Address  'if the cell changed location is...

        Case "$D$11"   '
    cell D11 then...
            
    With Sheets("Questionnaire")
                
    LR = .Range("S6555").End(xlUp).Row   'set LR to the last row in column S that contains a value
                    For Each c In .Range("S1:S" & LR).Cells  '
    loop through each cell in column S from row 1 to LR
                        
    If c.Value "HIDE" Then    'if the value in the current cell in the loop is equal to "HIDE"
                            c.RowHeight = 0 '
    then hide the row
                        End 
    If
                    
    Next c  'move to next cell in the loop
            End With
            
    End Select

    End Sub 
    The problem that I am having is that when rows are hidden from this macro, the related checkboxes are not hidden (I assume because they are objects on the spreadsheet). Is there a way to hide the checkbox on each row that is hidden - either by alterning the macro or some other means?

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

    Re: Hide checkbox when rows are hidden

    Hi akaempfe,

    If you know the name of each check box:

    Please Login or Register  to view this content.
    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

  3. #3
    Registered User
    Join Date
    09-12-2012
    Location
    KC
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Hide checkbox when rows are hidden

    The problem is they way the macro for hiding the rows is set up now - it's based on a value in each row (column S). I could change the macro to specifically hide the rows I need hidden (there are two different options, each of which hides a few rows). Would that be the best way to go about it?

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

    Re: Hide checkbox when rows are hidden

    Well, hiding the row won't hide the check box - it's better if you name the check box after the row, that way you'll be able to designate the proper check box to hide:

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

  5. #5
    Registered User
    Join Date
    09-12-2012
    Location
    KC
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Hide checkbox when rows are hidden

    How would I modify the original macro to take this into consideration? For instance, if the drop down menu on the "Menu" tab ($D$11) is set to equal one way (let's call it "Option 1"), then I would want rows 50-52 to be hidden on the "Questionnaire" tab. If the menu is "Option 2", then I need row 18 to be hidden.

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

    Re: Hide checkbox when rows are hidden

    If you name the checkboxes in such a way as they could be specified, then you can hide them at the same time as you hide the rows.

  7. #7
    Registered User
    Join Date
    09-12-2012
    Location
    KC
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Hide checkbox when rows are hidden

    I'm sorry for being a bit difficult here, but I'm not sure how to get this into the code. How would you insert this into the code I included above?

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

    Re: Hide checkbox when rows are hidden

    Hi akaempfe,

    Try this:

    Please Login or Register  to view this content.

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

    Re: Hide checkbox when rows are hidden

    Hi akaempfe,

    Try this:

    Please Login or Register  to view this content.
    The tolerance of "5" may be too one way or the other - you'll need to experiment.
    Last edited by xladept; 09-18-2012 at 03:15 PM.

  10. #10
    Registered User
    Join Date
    09-12-2012
    Location
    KC
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Hide checkbox when rows are hidden

    I haven't been able to get this to work after trying several difference tolerance levels. I went through and names each checkbox based on the checklist item. If the input on the "Instructions" tab is Option 1, then row 18 is hidden, which corresponds to Check Box 7. If the input on the "Instructions" tab is Option 2, then rows 50-52 are hidden, which corresponds to Check Box 18a and Check Box 18b. Would it be easier to build the specific items that need to be hidden into the macro based on their name?

    Also, can you explain what the O.Top and c.Top is doing in this formula?

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

    Re: Hide checkbox when rows are hidden

    Hi akaempfe,

    I found a way to find the name of the checkbox - o.top is the placement of the control, c.top is the placement of the cell - so, if they're in the "right" position, then that should be the checkbox to hide! Or, do you have the checkboxes elsewhere on the sheet???

    Can you supply a sample sheet?
    Last edited by xladept; 09-20-2012 at 03:26 PM.

  12. #12
    Registered User
    Join Date
    09-12-2012
    Location
    KC
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Hide checkbox when rows are hidden

    Here is the file. I have "redacted" the file to remove sensitive informaion, but you can see the basic format. Thanks.
    Attached Files Attached Files
    Last edited by akaempfe; 10-03-2012 at 08:22 AM.

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

    Re: Hide checkbox when rows are hidden

    Hi akaempfe,

    OK - so you've got Standard Controls - so we have to use "Shapes" since the Standard Controls have no properties - try this:

    Please Login or Register  to view this content.
    *There are some unnecessary variables included which were used in the debugging*

  14. #14
    Registered User
    Join Date
    09-12-2012
    Location
    KC
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Hide checkbox when rows are hidden

    The check boxes still aren't hiding on mine - are they hiding on the one you are looking at?

    Do I need to format the shapes differently? Right now, I have them as basically the same height as the cell, so I wasn't sure if that was causing a problem. I tried shrinking these down some, but it didn't seem to matter.

    Also, if there is an easier way to do this, I am open to that as well. I just need the checkboxes to be the inputs for people completing the checklist.

    Thanks.

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

    Re: Hide checkbox when rows are hidden

    Hi akaempfe,

    They're hiding on the Redact that you sent me - the same height as the cell is good - perhaps some test data?

    Here's how I tested it:

    Please Login or Register  to view this content.
    Last edited by xladept; 09-25-2012 at 12:36 PM.

  16. #16
    Registered User
    Join Date
    09-12-2012
    Location
    KC
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Hide checkbox when rows are hidden

    The rows are hiding properly when I select each option, but the boxes are just moving to the cell(s) below where the rows are hidden. I am just toggling between the two options on the drop down on the "Instructions" tab (ABC and XYZ). Is this what you are doing as well?

    Additionally, I am working on another thread to solve another problem. With the way the code is written, the rows do not unhide if you change from one option to another. Would you know how to address this problem as well?

    Thanks!
    Last edited by akaempfe; 09-25-2012 at 12:47 PM.

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

    Re: Hide checkbox when rows are hidden

    Hi akaempfe,

    No, I was testing it by writing HIDE in random rows of Column S.

    Your sample didn't include this sheet:
    Please Login or Register  to view this content.
    And, your sample doesn't recognize "ABC" OR "XYZ" as runtypeA. Value 1 or 2

    The only way I've gotten "HIDE" into Column S has been manually - that may be the key!


    Are you hiding the boxes first???
    Last edited by xladept; 09-25-2012 at 02:20 PM.

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

    Re: Hide checkbox when rows are hidden

    Hi akaempfe,

    I had it coded to just do one box at a time - so remove the "Exit For" from the inner loop:

    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    09-12-2012
    Location
    KC
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Hide checkbox when rows are hidden

    I'm still having some issues in getting the boxes to hide. Just to ensure there is no confusion, I have attached the spreadsheet that is updated to remove the "Exit for".
    Attached Files Attached Files
    Last edited by akaempfe; 10-03-2012 at 08:23 AM.

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

    Re: Hide checkbox when rows are hidden

    Hi akaempfe,

    I typed "HIDE" in P16 and CheckBoxes 5a,5b & 5c were hidden and then the entire row was hidden - as far as I can tell the code is working.

    I'd check out the logic of getting "HIDE" into the P's and Q's. ??????????????

  21. #21
    Registered User
    Join Date
    09-12-2012
    Location
    KC
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Hide checkbox when rows are hidden

    From the little I understand about macros, it matters what the actual "input" cell is for how the code should be written. For instance, I have columns P and Q set up as a formula to display "HIDE" based on what option is picked on the first tab. However, when you change the formula to the hard-keyed text "HIDE", it changes where the input is located. Will this affect how the code is written? I need the rows to hide based on the change made on the first tab, not typing into the cells in columns P and Q, as these will be hidden once the checklist is complete.

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

    Re: Hide checkbox when rows are hidden

    Hi akaempfe,

    There's no formula in the P and Q columns - so the hard coding does'nt hurt anything - the logic of placing the P and Q values is probably where the bug resides!

  23. #23
    Registered User
    Join Date
    09-12-2012
    Location
    KC
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Hide checkbox when rows are hidden

    There are formulas in Cells Q18 and P50-52 on the file I attached. These are the only rows that may be hidden - the rest will all be visible no matter what option you choose from the drop-down menu.

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

    Re: Hide checkbox when rows are hidden

    I tested with "ABC" and P50-52 disappeared just as they ought - there were no check boxes in 50 but all the rest hid as well as the rows - that doesn't work for you???

  25. #25
    Registered User
    Join Date
    09-12-2012
    Location
    KC
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Hide checkbox when rows are hidden

    No - when I choose ABC on the Instructions tab, it hides the rows properly but does not hide the checkbox.

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

    Re: Hide checkbox when rows are hidden

    I can't test this because I don't have "ClientTypeConsiderations" but see if if this workaround solves anything. Redaction.xls

  27. #27
    Registered User
    Join Date
    09-12-2012
    Location
    KC
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Hide checkbox when rows are hidden

    I'm not getting any of the rows to hide in this file.

    Where do you see "ClientTypeConsiderations" in the file?

    As a side note, I just wanted to thank you for helping me out on this. I know it's been a bit of a pain going back and forth like this, but I appreciate your help.

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

    Re: Hide checkbox when rows are hidden

    Hi akempfe,

    It's right up front in the code:


    Please Login or Register  to view this content.

  29. #29
    Registered User
    Join Date
    09-12-2012
    Location
    KC
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Hide checkbox when rows are hidden

    I don't know why, but I can't find the code you showed above.

    Here is the code I see on the "Instructions" tab:

    Please Login or Register  to view this content.
    And here is the code I see on the "Questionnaire" tab:

    Please Login or Register  to view this content.
    Can you tell me which tab you see the Client Type Considerations on?

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

    Re: Hide checkbox when rows are hidden

    Hi akaempfe,

    It's in Module1.

  31. #31
    Registered User
    Join Date
    09-12-2012
    Location
    KC
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Hide checkbox when rows are hidden

    OK - found what you were referring to. I think this was related to a macro from a workbook this was was rolled forward from. None of the recorded macros should be applied to this workbook though.

    As such, these macros should be deleted from this workbook, as they won't be necessary. The only macros I will need for this one is hiding/unhiding the rows and checkboxes on the Questionnaire tab. I was having some trouble getting rid of the unnecessary macros through, as Excel kept crashing when I tried to delete them. I'm not sure what that's about.

    Thanks.

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

    Re: Hide checkbox when rows are hidden

    Hi akaempfe,

    This works without every row in S with a formula - see if it's what you wanted:

    Redaction.xls

  33. #33
    Registered User
    Join Date
    09-12-2012
    Location
    KC
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Hide checkbox when rows are hidden

    It looks like after the macro was run, the checkboxes disappeared for good. If possible, I would like them to reappear if you switch from ABC to XYZ and vice versa. I cannot see checkbox 7, checkbox 18a or checbox 18b in the spreadsheet attached.

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

    Re: Hide checkbox when rows are hidden

    Try this:

    Please Login or Register  to view this content.

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

    Re: Hide checkbox when rows are hidden

    Hi akaempfe,

    If you're still there - it seems to be working now:

    Please Login or Register  to view this content.
    Last edited by xladept; 10-05-2012 at 07:23 PM.

  36. #36
    Registered User
    Join Date
    09-12-2012
    Location
    KC
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Hide checkbox when rows are hidden

    This fixes the issue of the boxes not reappearing and it looks like the rows are properly unhidden when you change options from one to the other.

    However, I am still having trouble getting the boxes to hide now. Is it still working for you?

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

    Re: Hide checkbox when rows are hidden

    Hi akaempfe,

    It's working perfectly for me now. Is this the version you're using?

    Redaction.xls

  38. #38
    Registered User
    Join Date
    09-12-2012
    Location
    KC
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Hide checkbox when rows are hidden

    When I open up that file, I can't see the first checkbox that is supposed to be hidden. Then when I choose the other option, that checkbox goes away as well. The rows are hiding and unhiding correctly, but it doesn't look like the boxes are.

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

    Re: Hide checkbox when rows are hidden

    It's just row 18 and rows 50-52 isn't it?

+ 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