+ Reply to Thread
Results 1 to 8 of 8

Userform: Have multiple checkbox values populate to one cell

Hybrid View

ciresuark Userform: Have multiple... 10-22-2014, 12:16 PM
judgeh59 Re: Userform: Have multiple... 10-22-2014, 12:27 PM
Norie Re: Userform: Have multiple... 10-22-2014, 12:27 PM
ciresuark Re: Userform: Have multiple... 10-22-2014, 12:36 PM
judgeh59 Re: Userform: Have multiple... 10-22-2014, 12:34 PM
judgeh59 Re: Userform: Have multiple... 10-22-2014, 12:38 PM
ciresuark Re: Userform: Have multiple... 10-22-2014, 12:42 PM
judgeh59 Re: Userform: Have multiple... 10-22-2014, 12:44 PM
  1. #1
    Registered User
    Join Date
    12-12-2013
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    92

    Userform: Have multiple checkbox values populate to one cell

    Hello,

    I am currently have a userform with 34 differnt check boxes. The check boxes are in a frame labeled as Codes. I currently have the code set up to enter the caption from the check box into a cell. If a user selects multiple check boxes, only one is currently entered into the cell.

    The code I am currently using is:

    If CheckBox5.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox5.Caption
    If CheckBox6.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox6.Caption
    If CheckBox7.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox7.Caption
    If CheckBox8.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox8.Caption
    If CheckBox9.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox9.Caption
    If CheckBox10.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox10.Caption
    If CheckBox11.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox11.Caption
    If CheckBox12.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox12.Caption
    If CheckBox13.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox13.Caption
    If CheckBox14.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox14.Caption
    If CheckBox15.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox15.Caption
    If CheckBox16.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox16.Caption
    If CheckBox17.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox17.Caption
    If CheckBox18.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox18.Caption
    If CheckBox19.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox19.Caption
    If CheckBox20.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox20.Caption
    If CheckBox21.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox21.Caption
    If CheckBox22.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox22.Caption
    If CheckBox23.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox23.Caption
    If CheckBox24.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox24.Caption
    If CheckBox25.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox25.Caption
    If CheckBox26.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox26.Caption
    If CheckBox27.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox27.Caption
    If CheckBox28.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox28.Caption
    If CheckBox29.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox29.Caption
    If CheckBox30.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox30.Caption
    If CheckBox31.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox31.Caption
    If CheckBox32.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox32.Caption
    If CheckBox33.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox33.Caption
    If CheckBox34.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox34.Caption
    If CheckBox35.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox35.Caption
    If CheckBox36.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox36.Caption
    If CheckBox37.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox37.Caption
    If CheckBox38.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox38.Caption
    If CheckBox39.Value = True Then Sheets("Log").Cells(emptyRow, 7).Value = CheckBox39.Caption
    Can this be modified to have multiple options put into (emptyRow, 7) separated by a comma?
    I have searched the forum and other forums and found similar questions; however the code I have tried I am not able to manipulate to work with what I have.

    Thank you for the help.

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Userform: Have multiple checkbox values populate to one cell

    this may work....it is completely untested because I don't have a bunch of checkboxes....but I believe the theory is sounds....this should replace all the IF's...

    
        Dim x As Integer
        
        For x = 5 To 39
            If CheckBox & x & .Value = True Then
                Sheets("Log").Cells(emptyRow, 7).Value = Sheets("Log").Cells(emptyRow, 7).Value & CheckBox & x & .Caption & ", "
            End If
        Next x
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Userform: Have multiple checkbox values populate to one cell

    Perhaps something like this.
    Dim I As Long
    Dim cnt As Long
    Dim arrCodes()
    
        For I = 5 To 39
            If Me.Controls("CheckBox" & I).Value Then
            ReDim Preserve arrCodes(cnt)
            arrCodes(cnt) = Me.Controls("CheckBox" & I).Caption
            cnt = cnt + 1
        Next I
        
        If cnt > 0 Then
            Sheets("Log").Cells(emptyRow, 7).Value = Join(arrCodes, ",")
        End If
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    12-12-2013
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Userform: Have multiple checkbox values populate to one cell

    For Judgeh59:
    I receive a run-time error '438': Object doesn't support this property or method and highlighted is
    If CheckBox & x & .Value = True Then
    For Norie:
    Compile error: Next without For and highlighted
    Next I

  5. #5
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Userform: Have multiple checkbox values populate to one cell

    my syntax won't work....Norie's looks like it will though....Go Norie

  6. #6
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Userform: Have multiple checkbox values populate to one cell

    Norie - looks like you left out the END IF....

        For I = 5 To 39
            If Me.Controls("CheckBox" & I).Value Then
                ReDim Preserve arrCodes(cnt)
                arrCodes(cnt) = Me.Controls("CheckBox" & I).Caption
                cnt = cnt + 1
            End If
        Next I

  7. #7
    Registered User
    Join Date
    12-12-2013
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: Userform: Have multiple checkbox values populate to one cell

    You got it! I added it in and it works wonderfully. Thank you all for your help!

  8. #8
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Userform: Have multiple checkbox values populate to one cell

    Great job Norie....I never played with the Controls object....thanks....

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. UserForm Checkbox populate last empty row of range
    By djsouljah in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-16-2013, 06:14 PM
  2. [SOLVED] Populate cell values into 6 named text boxes in a userform then edit if required
    By How How in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 03-05-2013, 05:51 AM
  3. Replies: 0
    Last Post: 11-15-2012, 12:29 PM
  4. Populate checkbox values in user form to cell
    By pavu in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-22-2012, 08:26 AM
  5. Populate checkbox values in user form to cell
    By in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-01-1970, 12:00 AM

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