+ Reply to Thread
Results 1 to 14 of 14

How to find the pixel length of a string

  1. #1
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    How to find the pixel length of a string

    Hi all,

    How do I find the pixel length of a string, so that I can find if it can be accommodated into a cell with a fixed length.

    I could find a similar post in the forum https://www.excelforum.com/showthread.php?t=530800. But it was not answered

    rgds

    johnjohns

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,621

    Re: How to find the pixel length of a string

    The default width of a cell is 8.43 characters. You can find the number of characters in a text string using the LEN() function. But, the number of characters you actually get in a cell without wrapping depends on the font and size you choose. Kerning also impacts since the letter "i" is not as wide as "H", etc.

    Maybe you should explain what you are trying to accomplish with such a calculation.
    Ben Van Johnson

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: How to find the pixel length of a string

    Using a fixed width font would be a good start.
    Remember what the dormouse said
    Feed your head

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to find the pixel length of a string

    Hello johnjohns,

    This UDF macro should help. The pixel size is dependent on the font size. If macro uses the default setting for your Excel application. You may want to use the cell 's font setting instead.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: How to find the pixel length of a string

    Thankyou ProtonLeah, Romperstomper, Leith Ross,

    I am afraid if I have not put my request clear enough. My intention is to split a sentence into many rows for better readability. For the words in cell B7, first 38 characters ("Up to 3 Citi Miles for every US Dollar") can fully fit into the width of column B. So I should be able to avoid the line
    Please Login or Register  to view this content.
    and take LettersPerLine as 38. And that will be my average number of characters per line. I am avoiding text wrapping. Can this be done?

    best regards

    johnjohns
    Attached Files Attached Files

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: How to find the pixel length of a string

    Did you look at cellproperties/wordwrap ?



  7. #7
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: How to find the pixel length of a string

    I did not get you fully, snb. Can you please provide the code?


    rgds
    johnjohns

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: How to find the pixel length of a string

    You don't need code.
    Select the cell, mouse rightclick / cellproperties / tab 'alignment' / wordwrap

  9. #9
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: How to find the pixel length of a string

    Hi snb
    I am using Excel 2003 and 2007. If it is 'Format Cells -> Alignment -> Wrap Text' , then that is not the requirement. I want the splitting to come in different rows. I think if you see the attachment it would be more clear.

    rgds

    johnjohns

  10. #10
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: How to find the pixel length of a string

    One weird way of doing it is
    Please Login or Register  to view this content.
    But that is too weird an approach. Any better ideas?

    rgds

    johnjohns

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: How to find the pixel length of a string

    If you set the Normal font to a fixed width font, then a column width of 38 will fit 38 letters, regardless of what they are. This then simplifies your task of breaking up the text.

  12. #12
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: How to find the pixel length of a string

    Hmm....it seems there are no better ways to do this other than what you all advised. I did a google search also. Thank you all

    rgds

    johnjohns

  13. #13
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: How to find the pixel length of a string

    You can use Word to do the trick:

    Please Login or Register  to view this content.
    Last edited by snb; 01-18-2011 at 10:07 AM.

  14. #14
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: How to find the pixel length of a string

    thanks snb. i will try and come back. it is time to leave the office

    rgds

    johnjohns

+ 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