I am running Excel 2010 and am trying to run this macro so that when a certain string is typed into any of five textboxes, a label's caption will change. For example:
Whenever I finish typing
I get an error message saying: “Compile Error: Expected: end of statement” and I can’t run without same error message showing and the “=” is highlighted in string. What is it I need to do to get “tb” to be recognized as TextBox object?
Code:
Dim tbNum as Integer
Dim tb as TextBox = DirectCast(Me.Contols(“Textbox” & tbNum.ToString), TextBox)
Private Sub TextBox1_Change()
txtChange
End Sub
Private Sub TextBox2_Change()
txtChange
End Sub
Private Sub TextBox3_Change()
txtChange
End Sub
Private Sub TextBox4_Change()
txtChange
End Sub
Private Sub TextBox5_Change()
txtChange
End Sub
Sub txtChange ()
If me.tb.text = “123” then
Label1.Caption = “Hello”
End If
If me.tb.text = “456” then
Label1.Caption = “Good-Bye”
End If
End Sub
Code:
Dim tb as TextBox = DirectCast(Me.Contols(“Textbox” & tbNum.ToString), TextBox)