+ Reply to Thread
Results 1 to 7 of 7

Macro or formula to display the number of characters per line within an Excel cell

  1. #1
    Registered User
    Join Date
    03-02-2016
    Location
    Osaka
    MS-Off Ver
    2007
    Posts
    3

    Macro or formula to display the number of characters per line within an Excel cell

    Dear all,

    My name is Carlos, nice to e-meet you!

    I have a special request and I was wondering if any of you have a workaround or a precise formula/macro to achieve it.

    Basically I have an Excel file with several character limitations, so some cells can only have one line of text, other can have from two up to three lines. Most of the conditions are that the cell has to have 60 characters the most. So I was wondering if there is the possibility to show how many characters there are in a line and the results shown separated by a comma.

    A visual example is the following:

    Character Limit to Meet Text Number of Characters per Line within a Cell
    60 characters * 2 lines This is an example, first line
    This is the second line
    30,23

    I hope any of you have a reply to this question.

    Best regards,

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Macro or formula to display the number of characters per line within an Excel cell

    Hi, welcome to the forum

    Assuming that your text is all in 1 cell, this is not as simple as it sounds

    with your data in A2...
    B2=LEN(LEFT(A2,FIND(CHAR(10),A2,1)))&" ,"&LEN(MID(A2,FIND(CHAR(10),A2,1)+1,99))
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    03-02-2016
    Location
    Osaka
    MS-Off Ver
    2007
    Posts
    3

    Re: Macro or formula to display the number of characters per line within an Excel cell

    Dear Ford,

    Thanks a lot for the quick and prompt reply.

    Yes, it's not simple as it sounds but it seems to be possible as once I saw it perfectly implemented in a file using VBA, it's a pity I never learned VBA.

    Regarding the formula that you shared, it seems to work fine when there are two lines in the cell, but when there is only one it shows #VALUE! and when there are three only the count of the first two lines is shown.

    Still, I really want to thank you for your reply! This is really helpful as it seems almost 80% of the cells I'm checking have two lines in one cell.

    Best regards,
    Carlos

    PS: I leave the thread as unsolved due the issues explained above.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Macro or formula to display the number of characters per line within an Excel cell

    OK try this...
    =LEN(LEFT(A2,IFERROR(FIND(CHAR(10),A2,1),99)))&IFERROR(" ,"&LEN(MID(A2,FIND(CHAR(10),A2,1)+1,99)),"")


    edit: oops missed the "3 lines" bit. Could there be more than 3?

  5. #5
    Forum Contributor
    Join Date
    06-02-2015
    Location
    delhi
    MS-Off Ver
    2010
    Posts
    104

    Re: Macro or formula to display the number of characters per line within an Excel cell

    Try this

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    02-24-2016
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    92

    Re: Macro or formula to display the number of characters per line within an Excel cell

    Hi,

    Based on post #5 I have created a function
    Please Login or Register  to view this content.
    to use it:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    WouterM
    The Netherlands

  7. #7
    Registered User
    Join Date
    03-02-2016
    Location
    Osaka
    MS-Off Ver
    2007
    Posts
    3

    Re: Macro or formula to display the number of characters per line within an Excel cell

    Dear WouterM and Mandeep Baluja,

    Thanks a lot for this function, it works perfectly fine and as expected!

    It counts the number of character per line, even if there are three lines or more.

    Regarding the previous formula, I just noticed it counts an extra character for the first file, I think it's counting the line break as a character and the third line doesn't shows up.

    Again, thanks a lot to everyone for your help!

    Best regards,
    Carlos

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] if characters in a cell > than a certain number, only display words under character limit
    By mcdermott2 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-08-2015, 06:27 AM
  2. Replies: 3
    Last Post: 05-18-2015, 11:53 PM
  3. checking number of characters in a cell macro
    By mehdoush in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-08-2014, 02:13 PM
  4. New line in cell after certain number of characters, or where a number stands
    By barqujo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-08-2013, 01:14 PM
  5. Limiting number of characters in a line
    By Amejin in forum Excel General
    Replies: 11
    Last Post: 11-21-2012, 10:17 PM
  6. Replies: 5
    Last Post: 10-19-2011, 12:27 PM
  7. [SOLVED] Is it possible to display the number of characters in a cell
    By Paul K. in forum Excel General
    Replies: 2
    Last Post: 11-03-2005, 06:40 AM

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