+ Reply to Thread
Results 1 to 14 of 14

Can check boxes be included in sorting, using VBA

  1. #1
    Registered User
    Join Date
    06-22-2011
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007/2010
    Posts
    16

    Can check boxes be included in sorting, using VBA

    I wish to sort a worksheet with a range B6:T50, based on column C. The sorting will be ascending alphabetically.
    My problem is that columns B and T have Active X Control checkboxes, and I have noted that they do not sort with the rest of the data.
    Is it possible, via a macro, to include the check boxes when sorting?
    Thanking you all in advance.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Can check boxes be included in sorting, using VBA

    You would make your life simpler if you used Marlett checkboxes, which are just values in cells. Search the forum for many examples.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    06-22-2011
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007/2010
    Posts
    16

    Re: Can check boxes be included in sorting, using VBA

    This is excellent. This will solve the sorting issue, thanks for that.

    However, I am having problems getting the second column of checkboxes working.
    The first works fine with the following code.


    Please Login or Register  to view this content.
    The second range of cells is named ‘NotinUse’.
    Any help amending this code to include the second column of checkboxes would be greatly appreciated.
    Last edited by grahamc; 07-24-2012 at 05:58 PM.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Can check boxes be included in sorting, using VBA

    I don't understand your question, Graham. Explain what you're trying to do in words.

  5. #5
    Registered User
    Join Date
    06-22-2011
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007/2010
    Posts
    16

    Re: Can check boxes be included in sorting, using VBA

    Hi shg,

    I have 2 columns of checkboxes on the one sheet. At the moment both columns are using Active X control checkboxes, but I want to replace both columns with Marlett checkboxes.
    The check boxes are located at B6:B50 & T6:T50.
    Using the above code and the Marlett font, I was able to successfully add the Marlett checkboxes to B6:B50. The name of the Range B6:B50 is 'Current'.
    My problem now is that I'm not sure how to update the code to incorporate the Marlett checkboxes in the second coloumn T6:T50.
    The name of the range T6:T50 is 'NotinUse'.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Can check boxes be included in sorting, using VBA

    You just want the same behavior in that range? What's the second code that sets the offset cells for?

  7. #7
    Registered User
    Join Date
    06-22-2011
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007/2010
    Posts
    16

    Re: Can check boxes be included in sorting, using VBA

    That's correct. Same behavior for both columns.

    The second code shows the user, the status selected. In the case of B6:B50 the 2 states are 'Current' & 'Non-Com' (short for Non-Compliant).
    The second column T6:T50 will also have a second code. It's offset cell will read 'Not in Use' if selected and remain blank if not selected.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Can check boxes be included in sorting, using VBA

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    06-22-2011
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007/2010
    Posts
    16

    Re: Can check boxes be included in sorting, using VBA

    Excellent shg. It works a treat. Thanks.
    I’m now having trouble with the second lot of code. I thought I might be able to handle it, but as I only tinker with Excel, it’s a bit beyond me.

    The code in question is:

    Please Login or Register  to view this content.
    The above code works well for the first column of Marlett checkboxes B6:B50 (Range Name: ‘Current’).
    I would like to add the same behaviours, in the above sub, to the second column of Marlett checkboxes T6:T50 (Range Name: ‘NotinUse’).


    Below is some code which illustrates what I’m after.

    Please Login or Register  to view this content.
    Thanks again for your help.

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Can check boxes be included in sorting, using VBA

    What doesn't work? What happens when you set a breakpoint and step throught the code?

    Spend 30 minutes reading http://www.cpearson.com/excel/debug.htm.

  11. #11
    Registered User
    Join Date
    06-22-2011
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007/2010
    Posts
    16

    Re: Can check boxes be included in sorting, using VBA

    I actually haven't completed the code.
    I started with a compile error. I resolved this when I learned I had the sub name in twice.
    I'll look over what you have sent and post a result soon.

    Thanks.

  12. #12
    Registered User
    Join Date
    06-22-2011
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007/2010
    Posts
    16

    Re: Can check boxes be included in sorting, using VBA

    I have acheived a result.


    Please Login or Register  to view this content.
    Do you think it needs any changes, as I have noticed that we novices tend to add superfluous lines to our code.

  13. #13
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Can check boxes be included in sorting, using VBA

    Perhaps ...

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    06-22-2011
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007/2010
    Posts
    16

    Re: Can check boxes be included in sorting, using VBA

    Perfect.
    Thanks again for all your help.

+ 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