Text Counter as you type

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to make a cell have a character counter? The cell is validated
to only allow 30 characters. I need to put in a counter that as the person
types, it shows they are on character "13/50" and keeps counting as they type.
 
So if I entered a text box, would this be possible?

If not, what is the most practical way to achive this?
 
Yes. A textbox from the control toolbox toolbar has a Change event that
fires on each keystroke, so this would support what you want to do.
 
Not to wear out your patience, but I am an extreme novice in VB. Do you have
a sample of the code I could manipulate?

Thanks again
 
put in a textbox from the control toolbox toolbar

Right click on it and select view code.

Put in code like this: (assumes the name is Textbox1)

Private Sub TextBox1_Change()
If Len(TextBox1.Text) > 30 Then
TextBox1.Value = Left(TextBox1.Text, 30)
End If
Set rng = TextBox1.TopLeftCell.Offset(0, -1)
rng.Value = "'" & Len(TextBox1.Text) & "/30"
End Sub
 
Works beautifully. Thanks again.


Tom Ogilvy said:
put in a textbox from the control toolbox toolbar

Right click on it and select view code.

Put in code like this: (assumes the name is Textbox1)

Private Sub TextBox1_Change()
If Len(TextBox1.Text) > 30 Then
TextBox1.Value = Left(TextBox1.Text, 30)
End If
Set rng = TextBox1.TopLeftCell.Offset(0, -1)
rng.Value = "'" & Len(TextBox1.Text) & "/30"
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top