How to select Items after dynamically creating CheckBox

aivin

New Member
Joined
Mar 29, 2024
Messages
8
Office Version
  1. 2016
Platform
  1. Windows
Hello,
I have what is supposed to be a simple problem with dynamic Checkbox. I'm making a list CheckBox in UserForm.

VBA Code:
Dim chkbox As MSForms.CheckBox
Dim i As Integer

For i = 1 To 3
   Set chkbox = Me.Controls.Add("Forms.Checkbox.1", "Checkbox_" & i)
    chkbox.Caption = "Test " & i
    chkbox.Left = 18
    chkbox.Top = 112 + ((i - 1) * 20)
    chkbox.Width = 108
    UserForm1.Height = 165 + ((i - 1) * 20)
Next x

As elsewhere in the code
How to choose and change the Caption for an example: Checkbox _2 witch Caption "Test 2" ?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
It looks like you want to change the caption for a specified CheckBox. If so, here's an example that changes the caption for Checkbox_2...

VBA Code:
UserForm1.Controls("Checkbox_2").Caption = "New Caption" 'change the caption as desired

Although, if the code resides in the UserForm code module, you can use the keyword Me to refer to the UserForm...

VBA Code:
Me.Controls("Checkbox_2").Caption = "New Caption" 'change the caption as desired

Hope this helps!
 
Upvote 0
Solution

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top