+ Reply to Thread
Results 1 to 2 of 2

Merging the correct number of cell rows to fit a string of wrapped text

  1. #1
    Registered User
    Join Date
    12-07-2006
    Posts
    36

    Merging the correct number of cell rows to fit a string of wrapped text

    Hi.

    I'm trying to write some code that merges the correct number of cell rows so that a cell of fixed width can contain a long string of text.
    The challenge is to merge the correct number of rows, so that when the text string is wrapped in the cell it is neither cut off (because too few rows have been merged), nor does it leave any empty rows at the end of the base of the merged cell (because too many rows have been merged.)

    I have tried estimating the number of characters that will fit across the width of the cell and then dividing the length of the text string (in characters) to calculate how many rows will be required to contain the whole string.
    But because I need to use Arial as the font for this (and not some font with fixed width characters, like Courier for example), counting the characters in the string does not give an accurate measure of how many rows are required to fit all the text.
    Also, because wrapping the text splits the string at unpredicatable points along its length (at the location of spaces, or hyphens - and I want it to do this), this adds to the difficulty of knowing how many rows will be required to fit all the text in the merged cell.

    What I find is that because my estimation of the number of characters that fit across the cell is only approximate, either the end of the text is cut off or there are too many rows (so there is a space at the bottom of the cell.)

    Is there another way to go about this?

    I have considered creating a list of the widths of each of the characters in the Arial font, so that I can make a more accurate estimate of the width of the character string, but this won't help with the unpredicatable break-points that arise when you wrap text.

    Is there an easier way of going about this?

    Any help you could give me with this issue would be greatly appreciated.

    Thanks.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Avoid using Merged Cells, they will generally be problematical. Can't you use a TextBox instead?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ 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