![]() |
Adding Checkboxes to a Form
Hello All,
Is there a way to use VBA to add a certain number of checkboxes (or anything else) to a userform? For example, I may need anywhere from 3 to 7 checkboxes on a userform. I would prefer to build just one instead of 5 different userforms. Thanks for the help. Bill |
Adding Checkboxes to a Form
Hi Bill
For such a limited task, I believe I'd create 7 boxes and set the visibility to False for the ones I don't need at runtime. But sure, see John Walkenbach's code at http://www.j-walk.com/ss/excel/tips/tip76.htm HTH. Best wishes Harald "Bill" skrev i melding ink.net... Hello All, Is there a way to use VBA to add a certain number of checkboxes (or anything else) to a userform? For example, I may need anywhere from 3 to 7 checkboxes on a userform. I would prefer to build just one instead of 5 different userforms. Thanks for the help. Bill |
Adding Checkboxes to a Form
I find it much simpler to add all the controls I need to the userform.
But hide them until they're needed (.visible = false) Bill wrote: Hello All, Is there a way to use VBA to add a certain number of checkboxes (or anything else) to a userform? For example, I may need anywhere from 3 to 7 checkboxes on a userform. I would prefer to build just one instead of 5 different userforms. Thanks for the help. Bill -- Dave Peterson |
Adding Checkboxes to a Form
Sub SpawnCheckBoxes()
Dim CheckBoxTotal As Long Dim cnt As Integer Dim myCB As Control CheckBoxTotal = Application.InputBox("How many CheckBoxes would you like?", "Creating CheckBoxes...", 3, , , , , 1) For cnt = 1 To CheckBoxTotal Set myCB = frmMyForm.Controls.Add("Forms.Checkbox.1", "myCB" & cnt) With myCB .Left = 0 .Top = (cnt * 15) - 15 .Object.Caption = "Hello From CheckBox" & cnt .Object.Value = True .Object.AutoSize = True End With Next frmMyForm.Show End Sub Try that post back if you have problems HTH Die_Another_Day Bill wrote: Hello All, Is there a way to use VBA to add a certain number of checkboxes (or anything else) to a userform? For example, I may need anywhere from 3 to 7 checkboxes on a userform. I would prefer to build just one instead of 5 different userforms. Thanks for the help. Bill |
All times are GMT +1. The time now is 08:04 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com