Count the number of Char in a textbox

jdavis9

Active Member
Joined
Mar 8, 2002
Messages
337
What I wish to accomplish is to count the number of characters in a text box and when the exceed a pre-determined number then enable a button.

ie. on a change count the number of char in the box

Private sub textbox1_change()
' count then number of char so far
if charactercount > 7 then
mybutton.enable = true
else:end if
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Does this work?

Code:
Private Sub TextBox1_change()
    If Len(TextBox1.Text) > 7 Then
        mybutton.Enabled = True
    End If
End Sub

Or how about this?

Code:
Private Sub TextBox1_change()
    mybutton.Enabled = Len(TextBox1.Text) > 7
End Sub
 
Upvote 0
Yes that works, I was making it much harder than needed.

Some days it's just better to stay in bed..........
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,937
Members
449,196
Latest member
Maxkapoor

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top