ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   For Each array - TextBoxes in a UserForm (https://www.excelbanter.com/excel-programming/379688-each-array-textboxes-userform.html)

excelnut1954

For Each array - TextBoxes in a UserForm
 
TextBoxe2 through TextBox21 might or might not be filled in by the
user. If any one is, then I want to go to a sub named EnterRecords.

I thought a For Each loop could work to test each TextBox for entry. I
know this is not correct syntax, but this is what I'm trying to do....

For Each (TextBox2 through Textbox21)
If TextBox*.Text = " " Then
EnterRecords
End If
Next

Am I close? Can it be this simple?
Thanks,
J.O.


excelnut1954

For Each array - TextBoxes in a UserForm
 
Thanks, Martin.
This worked fine. For future reference to anyone reading this, looking
for similar help, I had to change it slightly. Because I had the code
in a Standard Module, I had to change the 1st line to:
if UserForm3.controls("TextBox" & i) < "" Then

When I ran it the way it was written below, it gave me an error, but
Help was pretty clear on what I needed to do.

Thanks again for your help, and to others who contributed, too.
J.O.

Martin Fishlock wrote:
Hi:

Try this, you were quite close:

dim i as integer
For i=2 to 21
if me.controls("TextBox" & i) < "" Then
EnterRecords
End If
Next i

--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"excelnut1954" wrote:

TextBoxe2 through TextBox21 might or might not be filled in by the
user. If any one is, then I want to go to a sub named EnterRecords.

I thought a For Each loop could work to test each TextBox for entry. I
know this is not correct syntax, but this is what I'm trying to do....

For Each (TextBox2 through Textbox21)
If TextBox*.Text = " " Then
EnterRecords
End If
Next

Am I close? Can it be this simple?
Thanks,
J.O.





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

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