How to enter a Range of TextBoxes?

  • Thread starter Thread starter bg18461
  • Start date Start date
B

bg18461

Here is my redundant code,

TextBox1.Visible = False
TextBox2.Visible = False
TextBox3.Visible = False
TextBox4.Visible = False
TextBox5.Visible = False
TextBox6.Visible = False
TextBox7.Visible = False
TextBox8.Visible = False
TextBox9.Visible = False
TextBox10.Visible = False
TextBox11.Visible = False
TextBox12.Visible = False

Is there a easier way to enter a range of textboxes lik
(Textbox1:Textbox12).Visible = False. (This did not work).

P.S. - The textboxes are from the Control ToolBox
 
If they're located in a Userform:

Dim i As Long
For i = 1 to 12
Me.Controls("TextBox" & i).Visible = False
Next i
 
But as they are control tolbox textboxes use

Dim i As Long
For i = 1 To 12
Worksheets("Sheet1").OLEObjects("TextBox" & i).Visible = False
Next i


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Juan Pablo Gonzalez said:
If they're located in a Userform:

Dim i As Long
For i = 1 to 12
Me.Controls("TextBox" & i).Visible = False
Next i
 
Thanks for everyone's responses so far, I do appreciate it, now back t
the code.

Below shows the code and the error as I have it in my program, an
hints...

Private Sub OptionButton1_Click()
Dim i As Long
For i = 23 To 190
Worksheets("Sheet4").OLEObjects("Label" & i).Visible = False
Next i

ERROR:
Run-time error '9':
Subscript out of rang
 
That would suggest that Sheet4 doesn't exits, or one of the Texboxes 23 to
190 doesn't exist. When it occurs, get the error in debug.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Ok, I got rid of error 9 (subscript out of range) - wrong sheet name
however this error has been surplanted by 'Run-time error 438' - Objec
doesn't support this property or method.

Here is my code:

Dim i As Long
For i = 16 To 31
Worksheets("INSRD VEH PASS").OLEObjects("OptionButton" & i).BackColor
&HFFFF&
Next i

It appears to not like the OLEObjects method, but I cannot figure out
way around this. Any suggestions..
 
Try this

Dim i As Long
For i = 16 To 31
Worksheets("Sheet1").OLEObjects("OptionButton" & i).Object.BackColor =
&HFFFF&
Next i


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Of course, re-instate your sheetname, not my test sheetname


Worksheets("INSRD VEH PASS").OLEObjects("OptionButton" &
i).Object.BackColor = &HFFFF&

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Bob Phillips said:
Try this

Dim i As Long
For i = 16 To 31
Worksheets("Sheet1").OLEObjects("OptionButton" & i).Object.BackColor =
&HFFFF&
Next i


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
bg18461 said:
Thanks for everyone's responses so far, I do appreciate it, now back to
the code.

Below shows the code and the error as I have it in my program, any
hints...

Private Sub OptionButton1_Click()
Dim i As Long
For i = 23 To 190
Worksheets("Sheet4").OLEObjects("Label" & i).Visible = False
Next i

ERROR:
Run-time error '9':
Subscript out of range

Weren't you working with Textboxes, not Labels? If there are fewer
labels then textboxes then you'll get that error.

See ya
Ken McLennan
Qld Australia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top