+ Reply to Thread
Results 1 to 8 of 8

Display in a textbox, the character count of a cell, when the cell is selected

Hybrid View

  1. #1
    Registered User
    Join Date
    12-24-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    99

    Cool Display in a textbox, the character count of a cell, when the cell is selected

    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.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Display in a textbox, the character count of a cell, when the cell is selected

    Like this:

    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
    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.
    Last edited by stnkynts; 01-02-2013 at 06:05 PM.

  3. #3
    Registered User
    Join Date
    12-24-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    99

    Re: Display in a textbox, the character count of a cell, when the cell is selected

    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.

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Display in a textbox, the character count of a cell, when the cell is selected

    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

  5. #5
    Registered User
    Join Date
    12-24-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    99

    Re: Display in a textbox, the character count of a cell, when the cell is selected

    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 me Can 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


    Quote Originally Posted by stnkynts View Post
    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

  6. #6
    Registered User
    Join Date
    12-24-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    99

    Re: Display in a textbox, the character count of a cell, when the cell is selected

    @stnkynts: Need help! Can you please help me resolve this?

  7. #7
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Display in a textbox, the character count of a cell, when the cell is selected

    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

  8. #8
    Registered User
    Join Date
    12-24-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    99

    Re: Display in a textbox, the character count of a cell, when the cell is selected

    I used ActiveX textbox not sure why it isn't working for me. I hope i am clear in explaining what i am looking for. if not, I am trying to display the character count in a textbox when i select a cell.

    Quote Originally Posted by stnkynts View Post
    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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1