Looping through text boxes and checkbox captions on a user form

PioSwgr

New Member
Joined
Dec 22, 2023
Messages
8
Office Version
  1. 365
On a user form, I have 2 sets of 25 text boxes and 1 set of 25 checkbox named TextQty, TextPrice, CheckBox respectively. I am trying to pull the checkbox caption and the values inside the textboxes into a listbox if the checkbox is selected. I want to be loop through each set of the textboxes and checkboxes

code.png
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
1704402565904.png


This is the error code I get. Unsure how to loop properly thru this considering Im calling out a caption as well.
 
Upvote 0
Hi *PioSwgr. I don't quite follow the textbox values in the listbox if the checkbox is selected but this will probably get you started. You can loop through the controls of the userform and get information. You will need to adjust your userfom name to suit. HTH. Dave
Code:
Sub Test()
Dim ctl As Control
For Each ctl In UserForm1.Controls
If InStr(ctl.Name, "Text") Then
MsgBox UserForm1.Controls(ctl.Name).Value
End If
If InStr(ctl.Name, "Check") Then
MsgBox UserForm1.Controls(ctl.Name).Caption
End If
Next ctl
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,809
Messages
6,181,076
Members
453,020
Latest member
mattg2448

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