ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Looping thru TextBoxes (https://www.excelbanter.com/excel-programming/384831-looping-thru-textboxes.html)

John Pierce

Looping thru TextBoxes
 
I am trying to get some code to run in a series of textboxes on a
form. I found the bit of code below from Tom Ogilvy which appears
to be able to do that. I put it on a code sheet with Public Sub
LoopthruTextboxes() in front and End Sub at the end and ran it.
The form opens on the screen but nothing else happens. I'm
guessing that cntrl is not a keyword but a variable that needs to
be defined as an object(?) When I get this working would I just put
the code I want to repeat in place of "MsgBox cntrl.Name"?

For Each cntrl In UserForm1.Controls
i = 0
If TypeOf cntrl Is MSForms.TextBox Then
i = i + 1
MsgBox cntrl.Name
End If
Next


merjet

Looping thru TextBoxes
 
The problem is where you put the code. Put it the UserForm_Click()
event and click on the form when it appears (or have the
UserForm_Click() event call your Sub).

Merjet




All times are GMT +1. The time now is 09:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com