ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   loop through textboxes only (https://www.excelbanter.com/excel-programming/299018-loop-through-textboxes-only.html)

iwrk4dedpr[_3_]

loop through textboxes only
 
Greetings,

Use the following code to loop through controls on a userform

Sub ReadAllTextboxes()

Dim formControl As Control

For Each formControl In UserForm1

If TypeName(formControl ) = "TextBox" Then

. . . Your Code Here To Test Value

End If

Next formControl

End Sub

This should work for you

--
Message posted from http://www.ExcelForum.com


marwan hefnawy

loop through textboxes only
 
I have many textboxes in my userform and the userform contains other
controls such as labels ,option buttons and commandbuttons.
I want to read the value of each of my textboxes then decide the Backcolor
of each of them depending on its value.
Thats OK for me, but the problem is that I have to write some lines of code
for each textbox like that

if textbox1.value=.... then textbox1.backcolor=......
if textbox2.value=.... then textbox2.backcolor=......
etc..

Is there a way to loop through my textboxes to shorten my code?

i.e.

for each textbox in userform1.textboxes
if textbox.value=....... then textbox.backcolor=...
next

there is no such a collection as far as I know.

Any suggestions?

Thanks




All times are GMT +1. The time now is 01:56 PM.

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