VBA Character Count from Textbox

grabrail

Board Regular
Joined
Sep 6, 2010
Messages
128
Office Version
  1. 365
Platform
  1. Windows
I have created a text box and limited its max length to 53 character. I've also created a label that shows how many characters have been typed in the text box using the following:

VBA Code:
Private Sub FaultDetails_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Me.Label8 = Len(Me.FaultDetails.Value) + 1 & " / 53"
End Sub

Thsi works ok, and counts incrementally each character.

However, if i start typing and then delete some characters, it doesnt show the current length, e.g. if i typed hello there, the count goes up incrementally up to 11, if i then delete the "there" from the sentence it stays at 11 until i start typing something else.

How do i get it to regsiter the character deletions as the they are deleted?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Why don't you use Change event?
VBA Code:
Private Sub FaultDetails_Change()
  Me.Label8 = Len(Me.FaultDetails.Value) + 1 & " / 53"
End Sub
 
Upvote 0
Solution
Try using Change event:
VBA Code:
Private Sub FaultDetails_Change()
    Me.Label8 = Len(Me.FaultDetails.Value) + 1 & " / 53"
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,807
Members
449,339
Latest member
Cap N

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