Results 1 to 2 of 2

Thread: Set checkbox value to true
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Jun 2015
    Posts
    142
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Set checkbox value to true

    I have the following code that creates a list of checkbox items on my userform based on cell values on a worksheet. How can I set each of these checkboxes to default as true? If possible, I'm also looking for a way to set the size of the userform based on the number of checkboxes created. For example, the list of checkboxes to be created is dynamic, so sometimes there may be 5 or 6, other times there are 10-11. If there are more than 10, I'd like it to put the checkboxes in two columns and resize the userform accordingly.

    Code:
    Private Sub UserForm_Initialize()
    
    Dim curColumn   As Long
    Dim LastRow     As Long
    Dim i           As Long
    Dim chkBox      As MSForms.CheckBox
    
    
    curColumn = 1 'Set your column index here
    LastRow = Worksheets("sht_data").Cells(Rows.Count, curColumn).End(xlUp).Row
    
    
    For i = 5 To LastRow
        Set chkBox = Me.Controls.Add("Forms.CheckBox.1", "CheckBox_" & i)
        chkBox.Caption = Worksheets("sht_data").Cells(i, curColumn).Value
        chkBox.Left = 5
        chkBox.Top = 5 + ((i - 1) * 20)
    Next i
    
    
    End Sub
    Thanks for any time/help/input!

  2. #2
    Board Regular
    Join Date
    Jun 2015
    Posts
    142
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Set checkbox value to true

    I just got checkboxes to set as TRUE....any help on the other part of the question would be greatly appreciated! Thanks.

    Code:
    For Each ctrl In Me.Controls    ctrl.Value = True
    Next ctrl

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •