Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Easy One - Syntax for variables in TextBox & Label names
Hello:
What is the correct syntax for including a variable (in this case "i") in the name of a TextBox and/or Label? I have a list of TextBoxes and Labels on a userform and I want to program a reset button to change what is displayed back to the defaults. I need something like this: Private Sub CommandButton8_Click() For i = 1 To 13 TextBox(i).Text = "0" Label(i).Caption = "N/A" Next i End Sub I'm getting a Sub or Function not defined error, and I know it's because the syntax is wrong. Help is appreciated. Thanks, MARTY |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Easy One - Syntax for variables in TextBox & Label names
Could be looking for the parent to the textbox and label. i.e.
UserForm1.TextBox(i) and UserForm1.Label(i), etc. "Marty" wrote: Hello: What is the correct syntax for including a variable (in this case "i") in the name of a TextBox and/or Label? I have a list of TextBoxes and Labels on a userform and I want to program a reset button to change what is displayed back to the defaults. I need something like this: Private Sub CommandButton8_Click() For i = 1 To 13 TextBox(i).Text = "0" Label(i).Caption = "N/A" Next i End Sub I'm getting a Sub or Function not defined error, and I know it's because the syntax is wrong. Help is appreciated. Thanks, MARTY |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Easy One - Syntax for variables in TextBox & Label names
For i = 1 To 13
Controls("TextBox" & i).Value = "0" Controls("Label" & i).Caption = "N/A" Next i Hth, Merjet |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Easy One - Syntax for variables in TextBox & Label names
Nope. I tried this as a test based on your respone:
Private Sub CommandButton8_Click() For i = 9 To 13 DATAENTRY.TextBox(i).Text = "0" Next i End Sub and now I get a "method or data member not found" error. The ".TextBox" part is highlighted while the error message is up, so apparently it doesn't like "TextBox" without an integer suffix. This is what I'm trying to do: make a variable suffix. Other ideas? "JLGWhiz" wrote: Could be looking for the parent to the textbox and label. i.e. UserForm1.TextBox(i) and UserForm1.Label(i), etc. "Marty" wrote: Hello: What is the correct syntax for including a variable (in this case "i") in the name of a TextBox and/or Label? I have a list of TextBoxes and Labels on a userform and I want to program a reset button to change what is displayed back to the defaults. I need something like this: Private Sub CommandButton8_Click() For i = 1 To 13 TextBox(i).Text = "0" Label(i).Caption = "N/A" Next i End Sub I'm getting a Sub or Function not defined error, and I know it's because the syntax is wrong. Help is appreciated. Thanks, MARTY |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Easy One - Syntax for variables in TextBox & Label names
Hi
the code below is one way to do it Option Explicit Dim Ctrl As Control Dim i As Integer Private Sub CommandButton1_Click() For i = 1 To 13 Set Ctrl = Me.Controls("TextBox" & i) Ctrl.Value = "" Set Ctrl = Me.Controls("Label" & i) Ctrl.Caption = "" Next End Sub Hope this helps Steve |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Easy One - Syntax for variables in TextBox & Label names
Perfect. Thanks.
"merjet" wrote: For i = 1 To 13 Controls("TextBox" & i).Value = "0" Controls("Label" & i).Caption = "N/A" Next i Hth, Merjet |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Easy Syntax question: referring to worksheet by VBA name | Excel Programming | |||
Is there an easy way calculate 2 variables in conditional sum wiz. | Excel Worksheet Functions | |||
Easy VBA Syntax Question | Excel Programming | |||
Easy VBA Syntax Question | Excel Programming | |||
easy question : textbox | Excel Programming |