I have a userform that will have multiple text boxes for users to edit data pulled from one of the Sheets.
In that userform I have corresponding labels for each text box to show the number of characters each has.
I want each respective label to update their caption to be displayed as the user is editing each text box.
The method I have come across to do this is by using a Class module.
However, I am having an issue with the label caption not displaying on the userform.
The below code is an example of the code I'm using on just a single text box and single corresponding label named ItemNumber and ItemNumberLength respectively:
Private WithEvents MyTextBox As MSForms.TextBox Public Property Set Control(tb As MSForms.TextBox) Set MyTextBox = tb End Property Private Sub MyTextBox_Change() Call Userform1.PersistentUpdate_ItemNumber End Sub
Dim tbCollection As Collection Private Sub UserForm_Initialize() Dim ctrl As MSForms.Control Dim obj As clsTextBox Set tbCollection = New Collection For Each ctrl In Me.Controls If TypeOf ctrl Is MSForms.TextBox Then Set obj = New clsTextBox Set obj.Control = ctrl tbCollection.Add obj End If Next ctrl Set obj = Nothing End Sub Public Sub PersistentUpdate_ItemNumber() ItemNumberLength.Caption = Len(ItemNumber.Text) End Sub
Thanks in advance!