Can we display character count in a textbox (placed in a sheet), when the cell is selected? Please suggest any better way of achieving this? I want to avoid the usage of button/msgbox.
Can we display character count in a textbox (placed in a sheet), when the cell is selected? Please suggest any better way of achieving this? I want to avoid the usage of button/msgbox.
Like this:
You will need to use an activex TextBox for this to work. Put the code in the Worksheet Change event. Edit the range and name of textbox according to your need.![]()
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("A1")) Is Nothing Then TextBox1.Text = Len(Sheets("Sheet1").Range("A1").Value) End If End Sub
Last edited by stnkynts; 01-02-2013 at 06:05 PM.
How can i make this work for any cell i click on a worksheet? Also, i need to know if we can implement for a range of cells say A1:A10. I want to try both these cases.
Well, it depends. If you have just 1 textbox called textbox1 then its easy. If you have multiple textboxes I am going to need a lot more information. This will do range "A1:A10". You should be able to see the differnce to modify yourself.
![]()
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("A1:A10")) Is Nothing Then TextBox1.Text = Len(Target.Value) End If End Sub
Hi! Thanks for the response. I am using only one textbox to display character count of a cell. I tried your code, but somehow it didn't work for meCan you please suggest what i need to modify here?
![]()
Private Sub Worksheet_Change(ByVal Target As Range) Dim WS2 As Worksheet, LRow As Long Set WS2 = Worksheets("Sheet2") LRow = WS2.Range("A" & Rows.Count).End(xlUp).Row If Not Intersect(Target, Range("F5:F" & LRow)) Is Nothing Then TextBox1.Text = Len(Target.Value) End If End Sub
@stnkynts: Need help! Can you please help me resolve this?
This works just fine for me. Are you sure your using an ActiveX textbox titles TextBox1?
![]()
Private Sub Worksheet_Change(ByVal Target As Range) Dim LRow As Long LRow = Sheets("Sheet2").Range("F" & Rows.Count).End(xlUp).Row If Not Intersect(Target, Range("F5:F" & LRow)) Is Nothing Then TextBox1.Text = Len(Target.Value) End If End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks