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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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
That's exactly what I meant. thanks for your help !
 
Upvote 0
You're very welcome, I'm glad I could help.

Cheers!
 
Upvote 0

Forum statistics

Threads
1,215,085
Messages
6,123,030
Members
449,092
Latest member
ikke

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