+ Reply to Thread
Results 1 to 3 of 3

text length

  1. #1
    Registered User
    Join Date
    12-29-2004
    Posts
    37

    Question text length

    Hi,

    looking for a line of code to check and make sure that there are no more than 40 characters including blanks within a cell. I know it's something to do with validating data, but can't come up with anything as far as VB codes for it.
    or len()......something something - can't quite get it, that why I here. would appreciate any help on this matter.

    Thank You,
    -zerosleep

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996
    No VBA necessary (if you catch it upon entry):

    Data>Validation
    Allow: Text Length
    Data: less than or Equal To
    Maximum: 40


    But, if you must check after the fact, here's some sample code:


    Option Explicit
    Sub Max40()
    Dim theCell As Range
    For Each theCell In [TestRange]
    If Len(theCell.Value) > 40 Then
    theCell.Value = Left(theCell.Value, 40)
    End If
    Next theCell
    End Sub


    Does that help?

    Regards,
    Ron
    Last edited by Ron Coderre; 04-13-2005 at 04:45 PM.

  3. #3
    Registered User
    Join Date
    12-29-2004
    Posts
    37

    validate

    Actually the data is usually already entered(sometime a whole lot of it).
    and I was looking to just run a macros that would loop thru the selected cell and make sure they're not more than 40 characters long- if they are, color the cell or something indicating it's over the 40 limit. Thank for the suggestion though.

    -zerosleep


    thanks! just what i was looking for.
    Last edited by zerosleep; 04-15-2005 at 04:53 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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