Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

excel form checkboxes

hello all,

is there a faster way in vba to add multiple check-boxes in a form in excel? the checkbox names could be checkbox1,checkbox2,checkbox3.....etc

i have create 35 checkboxes within a form and then do the same for other forms as well...so this is kind of pain

Thank you
0
Rayne
Asked:
Rayne
  • 4
  • 2
1 Solution
 
NorieVBA ExpertCommented:
Do you mean a userform or a form on a worksheet?

For a userform you could use something like this.
Private Sub UserForm_Initialize()
Dim chk As MSForms.Checkbox
Dim lngTop As Long

    lngTop = 5

    For I = 1 To 35
        Set chk = Me.Controls.Add("Forms.CheckBox.1, "CheckBox" & I)
        chk.Top = lngTop
        lngTop = lngTop+chk.Height+5
    Next I

End Sub

Open in new window

That puts all the checkboxes in one column which might not be suitable but the code can be refined to place them in some other configuration.

Similar code can be created if the form is on a sheet.

By the way, you could use a listbox with MultiSelect set to fmMultiSelectMulti and ListStyle set to fmListStyleOption.

That would show a chekcbox next to each item in the listbox.
0
 
RayneAuthor Commented:
Thank you Imnorie, that is awesome
how can use the listbox - how can i populate the list box with data set from one column in worksheet - please assist
0
 
RayneAuthor Commented:
so the question is > how do i add a set of vlaues in a worksheet to that awesome list box you mentioned? I am not able to populate the listbox so far..

Thank you
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
RayneAuthor Commented:
you are awesome imnorie, you saved me a huge chunk of time - listbox rocks, checkboxes not.....thank you thank you , i got it :)
0
 
NorieVBA ExpertCommented:
I take it you figured out the listbox?

If you didn't here's a simple example that populates a listbox from A2:A35 on Sheet1 and sets it up to display checkboxes.
Private Sub UserForm_Initialize()

    With Me.ListBox1
        .List = Sheets("Sheet1").Range("A2:A35").Value
        .ListStyle = fmListStyleOption
        .MultiSelect = fmMultiSelectMulti
    End With

End Sub

Open in new window

0
 
RayneAuthor Commented:
Thank you Imnorie,

This is Perfection to the ULTIMATE, thank you, thank you :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now