Using checkboxes to sort data

  • Hi there,


    I have a list of text and next to each cell I have a checkbox. Is there any way to - when a checkbox is selected for the text in the cells next to the text box to appear in a list somewhere else i.e. producing a list of only checked text.


    Sorry for the poor explanation - any help with checkboxes and named ranges might help though I think!


    Thanks,
    Jennie
    :)

  • Re: Using checkboxes to sort data


    Hi Jennie,


    Several questions would need to be asked in order to clarify your constraints ...


    or ... much easier ... why don't you attach a worksheet sample ... :smile:

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Re: Using checkboxes to sort data


    Hi Jennie,


    Thanks a lot for your sample worksheet ...


    Congratulations on your smart conditional formatting ...!!!


    Once a given number of checkboxes are ticked ... what would be precisely your objective ?

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Re: Using checkboxes to sort data


    Rather than all those checkboxes (I assume your working version will have many more rows than your example), I prefer to use Martlett Checkboxes. (Note that your attachment is 60K, the one without the checkboxes is 26K)


    Double click on a cell in column B to put an X (or remove it)


    I think this might do what you are looking for.

  • Re: Using checkboxes to sort data


    How did you do this you wizard!?!!


    That's exactly what I'm looking for it to do. But I have no clue how you've done it s:

  • Re: Using checkboxes to sort data


    Haha thanks very much, I was a little too proud of myself for the formatting!


    What I wanted to do is as mikerickson has shown - sorting it so checked groups are copied to another location and sorted.

  • Re: Using checkboxes to sort data


    Hi,


    I'm very new to VBA but am trying to work through it so please excuse the stupid questions...! I'm not sure what your 'sourceValues', 'otherValues' and 'otherPlace' are? Are these named ranges or something else?


    Thanks again!

  • Re: Using checkboxes to sort data


    They are declared in the procedure...

    Code
    Dim sourceValues As Variant, otherValues As Variant
        Dim otherPlace As Range


    A 'Variant' is a non-specific type of variable - it can refer to anything. Contrast with

    Code
    Dim strName as String
    Dim OtherPlace as Range


    Which can only be a String and a reference to a Range of cells on a worksheet, respectively.


    A little later, SourceValues is set to refer to a range of cells and OtheValues simply a copy of SourceValues

    Code
    sourceValues = .CurrentRegion.Value
                otherValues = sourceValues


    Near the top of the procedure, OtherPlace is set to refer to cell G1

    Code
    Set otherPlace = Range("G1")


    And near the End, OtherPlace is resized to the same size as the array SourceValues, that range is cleared and then populated with the contents of OtherValues.

    Code
    otherPlace.Resize(1, UBound(sourceValues, 2)).EntireColumn.ClearContents
               otherPlace.Resize(Pointer, UBound(sourceValues, 2)).Value = otherValues


    Even though the code 'switches' between SourceValues and OtherValues, they are exactly the same size, the only difference is OtherValues (remember, both are arrays) contains the sorted values so that is what is written back to the worksheet.

  • Re: Using checkboxes to sort data


    Thanks cytop for the complete explanation of the VBA code ... :smile:


    Should Jennie be willing to keep the tick off symbol, she could use ü and the wingdings font ...


    Cheers

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Re: Using checkboxes to sort data


    Hellooo,


    The bit I can't get my head around is what you change to have this apply to further down the worksheet i.e. starting from cell A10 instead of cell A1 (with the header missed out.


    Any pointers would be greatly appreciated!

  • Re: Using checkboxes to sort data


    Oh, thanks very much for the explanation!! Sorry I didn't see that before replying.


    I get that you set a range of cells (i.e. sourceValues) to a type of variable after your explanation - but how do you actually set what cells are in your cell range? As in how do I set sourceValues to a given range, say the area covering A18 to F30? I also realise the header has been ignored somehow - is this something to do with the resize?


    Thanks very much!
    Jen

  • Re: Using checkboxes to sort data


    There are two Location codes in that routine.
    The first is the test

    Code
    With Target
            If .Column = 2 Then


    Which asks "is the double clicked cell in column B, if so, treat it like a checkbox"


    One could alter the test to

    Code
    If .Column = 2 and 17 < .Row Then

    which would make only cells B18 and below the "checkbox cells"


    Code
    If .Column = 2 and 17 < .Row And .Row < 31 Then

    would make only cells B18:B30 the "checkbox cells"


    The other location line is the one that sets the whole source range.

    Code
    Set SourceRange = Target.CurrentRegion


    If you leave a blank row and column on each side of the source range, then there is no need to alter that line.
    Alternantly you could explicitly set the source range to what you want

    Code
    Set SourceRange = Range("A18:F30")
  • Re: Using checkboxes to sort data


    Quote from mikerickson;760970

    Rather than all those checkboxes (I assume your working version will have many more rows than your example), I prefer to use Martlett Checkboxes. (Note that your attachment is 60K, the one without the checkboxes is 26K)


    Double click on a cell in column B to put an X (or remove it)


    I think this might do what you are looking for.


    I know this thread is a couple months old, but I could really use some help if you're willing.


    I am looking for something similar to this, but I can't seem to interpret the code enough to make the changes I need to make. I don't have any coding skills, so a lot of it just doesn't make sense. I tried to make some sense of your further explanations in this thread on sourceValues/otherValues/etc., but I couldn't figure it out. I need where it's pasted (otherPlace?) to be on a different sheet, and I don't want the column that is checked (the Martlett Checkboxes?) visible in the pasted section. Ideally, I would move the checkbox column to column A, then have it copy/paste the rest of the row into another pre-made sheet (don't need it to auto-create the sheet). Thanks in advance for any direction.

  • Re: Using checkboxes to sort data


    Hi,


    To be on the safe side, and sure to get your customized solution ... why don't you attach your excel file in your next message ...


    HTH

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Re: Using checkboxes to sort data


    Quote from Carim;763206

    Hi,


    To be on the safe side, and sure to get your customized solution ... why don't you attach your excel file in your next message ...


    HTH


    I'm actually just playing around with the TickboxExample2 in post 6 of this thread, trying to figure out how to modify the code. What I'm trying to do is set up a sheet with a bunch of football plays, and then when those plays are checked on sheet1, they will be copied to sheet2. Kind of like a game sheet that will be changing weekly. Like I said, I'm not real savvy when it comes to coding, but I can usually figure some of the easier stuff out. My complete lack of knowledge in visual basic is showing through on this, though. I usually accomplish everything using formulas, but that just won't cut it for this.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!