Hello.
I have 50+ embedded text boxes in my active sheet and I would like to apply a formula to all of the text boxes without having to rewrite the code for each textbox.
I am new to VBA and I have read about the possibility of using classes but I do not understand how I can make them work. I also did not enter my textboxes into a form which seems to be popular judging by the searches but I did not see a reason to use them. Should I have used a form? Any help with explaining how to write the code and explaining would be greatly appreciated.
Here are a few examples of the textbox names. Every text box starts with txt.
txtFirstYear011
txtName011
txtAddress011
txtRepeat011
Here is an example of a procedure that I would like to occur for every textbox in the active workbook whenever any of the textboxes gain focus.
Private Sub txtFirstYear011_GotFocus()
'Selects all data within the textbox when it gains focus.
txtFirstYear011.SelStart = 0
txtFirstYear011.SelLength = Len(txtFirstYear011.Text)
End Sub
Here is another sample code that I would like to apply to all textboxes.
Private Sub txtFirstYear011_LostFocus()
'Makes the entered number a percent.
txtFirstYear011.Value = Format(Val(txtFirstYear011.Value) / 100, "0.00%")
txtFirstYear011.SelStart = Len(txtFirstYear011.Value) - 1
End Sub
Thank you for your time.
I have 50+ embedded text boxes in my active sheet and I would like to apply a formula to all of the text boxes without having to rewrite the code for each textbox.
I am new to VBA and I have read about the possibility of using classes but I do not understand how I can make them work. I also did not enter my textboxes into a form which seems to be popular judging by the searches but I did not see a reason to use them. Should I have used a form? Any help with explaining how to write the code and explaining would be greatly appreciated.
Here are a few examples of the textbox names. Every text box starts with txt.
txtFirstYear011
txtName011
txtAddress011
txtRepeat011
Here is an example of a procedure that I would like to occur for every textbox in the active workbook whenever any of the textboxes gain focus.
Private Sub txtFirstYear011_GotFocus()
'Selects all data within the textbox when it gains focus.
txtFirstYear011.SelStart = 0
txtFirstYear011.SelLength = Len(txtFirstYear011.Text)
End Sub
Here is another sample code that I would like to apply to all textboxes.
Private Sub txtFirstYear011_LostFocus()
'Makes the entered number a percent.
txtFirstYear011.Value = Format(Val(txtFirstYear011.Value) / 100, "0.00%")
txtFirstYear011.SelStart = Len(txtFirstYear011.Value) - 1
End Sub
Thank you for your time.