+ Reply to Thread
Results 1 to 9 of 9

If / then statement for character length within a cell

  1. #1
    Registered User
    Join Date
    08-21-2012
    Location
    Illinois
    MS-Off Ver
    Excel 2013
    Posts
    27

    If / then statement for character length within a cell

    Hi everyone,
    My first post here on the forum. Am hoping to find a snippet of code to include in my macro that looks thru a column of text and alerts me (preferrably by just coloring the cell) if the cell is larger than 66 characters. The cell will always only contain a string of text.

    It will look something like this in column "E":

    COPPELL TEX INDPT SCH DIST
    WASHINGTON ST
    ALABAMA ST PUB SCH & COLLEGE AUTH
    JOHNSON CNTY KANS CMNTY COLLEGE STUDENT COMMONS & PKG SYS REV
    HAWAII ST
    ILLINOIS HSG DEV AUTH REV
    SNOHOMISH CNTY WASH SCH DIST NO 015 EDMONDS

    I gave something like this a try, but no cigar.... Any help appreciated!


    Please Login or Register  to view this content.
    Last edited by Cutter; 08-22-2012 at 07:25 PM. Reason: Added code tags

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: If / then statement for character length within a cell

    Why complicate the process with a macro when it's far simpler to apply a conditional format to the range in question?

    Never use VBA when there is bog standard Excel functionality.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    08-21-2012
    Location
    Illinois
    MS-Off Ver
    Excel 2013
    Posts
    27

    Re: If / then statement for character length within a cell

    Richard,
    Thanks for your reply. Of course. I was just not aware of a conditional cell formatting that could count characters inside the cell.
    Kerry

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: If / then statement for character length within a cell

    Conditional format formulae are no different to formulae you enter directly on the sheet. Usually you are getting them to evaluate to a True or False. So in your case

    =LEN(A1)>66

  5. #5
    Registered User
    Join Date
    08-21-2012
    Location
    Illinois
    MS-Off Ver
    Excel 2013
    Posts
    27

    Re: If / then statement for character length within a cell

    Thanks Richard, although again would love if it didn't return false but returned a green color cell.

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: If / then statement for character length within a cell

    Hi,

    Not sure what you mean.

    It sounds like you entered that formula directly in a cell. You should be entering it in the conditional format FOR that cell.

  7. #7
    Registered User
    Join Date
    08-21-2012
    Location
    Illinois
    MS-Off Ver
    Excel 2013
    Posts
    27

    Thumbs up Re: If / then statement for character length within a cell

    Solved! Got it into a nice little macro if anyone else needs something like this!


    Please Login or Register  to view this content.
    Last edited by Cutter; 08-23-2012 at 01:52 PM. Reason: Added code tags

  8. #8
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: If / then statement for character length within a cell

    @ kerrya98

    Welcome to the forum.

    Please notice that code tags have been added to your post(s). The forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at top of the page and read Rule #3.
    Thanks.

    Based on your last post it seems that you solved your problem on your own but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

  9. #9
    Registered User
    Join Date
    08-21-2012
    Location
    Illinois
    MS-Off Ver
    Excel 2013
    Posts
    27

    Re: If / then statement for character length within a cell

    Thanks for the head's up. Will do all that in the future!

+ 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