+ Reply to Thread
Results 1 to 4 of 4

List names of selected checkboxes in UserForm as string

  1. #1
    Registered User
    Join Date
    09-27-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    List names of selected checkboxes in UserForm as string

    Noob question from a first-time poster:

    Okay, so basically I have a macro that is doing a bunch of stuff, but I'll just give you the pertinent information. I have a UserForm with a bunch of checkboxes, and I basically want it to spit out a string with a list of all of the checkbox names of all the checked boxes. And then I'll use that string elsewhere in a Range(...).Select command.

    This is as far as I've gotten...

    Please Login or Register  to view this content.
    So it's checking each box and returning the Name as the variable "Selected Columns", but how can I get that to list it out so that each of those names goes into another section like this...

    Please Login or Register  to view this content.
    ...where C1, D1, etc. will be replaced with the names of each checkbox.

    Let me know if that makes sense, or if I need to add more information. Thanks! (Excel 2010)

  2. #2
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: List names of selected checkboxes in UserForm as string

    try changing this line: SelectedColumns = ctrl.Name
    to this: SelectedColumns = SelectedColumns & ctrl.Name

    UNTESTED.....
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

  3. #3
    Registered User
    Join Date
    09-27-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: List names of selected checkboxes in UserForm as string

    Unfortunately, that gave an error. That's where I'm establishing the variable, so I think it needs to be "=". But I took your idea and tried...

    Please Login or Register  to view this content.
    ...which unfortunately also didn't work, it just listed each one on the msgbox twice. I need it to list each one in the same list at the same time. I'm sure it's some simple little syntax thing I'm missing...

  4. #4
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: List names of selected checkboxes in UserForm as string

    Here's the basic concept:
    On the first pass through the control set, it should grab the current control name if it's value = TRUE. It should then take the variable SelectedColumns which should be empty and append an empty string (which is the current value of SelectedColumns before adding anything to it). To that empty string it should add the control name, so your variable should hold ""FirstFoundControlName. On the second pass through it should look like FirstFoundControlNameSecondFoundControlName. You'll need to add commas to separate each control name.

    SelectedColumns = SelectedColumns & "," & ctrl.Name

    Hope that helps...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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