+ Reply to Thread
Results 1 to 6 of 6

Bypass justify

  1. #1
    Registered User
    Join Date
    10-30-2024
    Location
    Sweden
    MS-Off Ver
    365
    Posts
    3

    Question Bypass justify

    Hello,

    I would like to write protocols in Excel to be able to store them all in the same file. What I haven't thought about is that the line breaks are adjusted strictly between the lines, which means that longer texts increase the line height so much that the text is moved to the next page. This means that virtually all pages contain too much empty space of rows.

    Hence I have looked at the possibility of using the method justify in VBA, but the problem is that it only regulates up to 255 characters and discards the rest. Is there a way to bypass this with VBA? I want to store everything that is written in B1 in a named variable 'MyText' and ensure that VBA then picks out whole words up to the maximum limit of 255 characters, which then spills out to the cells below. After that to pick the next 255 characters from the MyText variable and then continue spilling where the previous string left off.

    In Excel, I think the formula could look something like this, however, this is not with full words and without knowing in which row to put the next function:

    LEFT(B1,255)

    MID(B1,255+1,255)

    MID(B1,255+255+1,255)

    Is there anyone who had made a solution to this before or know how to do this in VBA?

    Best regards
    Tim
    Last edited by timsoderstrom.se; 11-03-2024 at 02:08 AM.

  2. #2
    Registered User
    Join Date
    11-01-2024
    Location
    Korea
    MS-Off Ver
    M365 64bit v2410
    Posts
    185

    Re: Bypass justify

    Try this formula.
    But it has a drawback, it can't distinguish between words, so it cuts through the middle of a WORD.

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    10-30-2024
    Location
    Sweden
    MS-Off Ver
    365
    Posts
    3

    Re: Bypass justify

    Hi,

    Thanks, interesting formula. I had to test it with 95 characters instead of 255 because the formula also spilled into cells on the right. However, I am looking for a solution in VBA that checks how many characters fit in the existing cell width before the text spills down, and unfortunately it has to be in whole words. That is, something that simulates Justify but with more characters than just its limitation of 255 characters. However, your formula could work if you only get all whole words and that no new lines start with spaces.

    Best regards
    Tim

  4. #4
    Registered User
    Join Date
    11-01-2024
    Location
    Korea
    MS-Off Ver
    M365 64bit v2410
    Posts
    185

    Re: Bypass justify

    I made a UDF what you want.
    It has two parameters, the first is TEXT to be splitted, the second is LENGTH of lines.
    The second parameter is optional, could be omitted, it's default value is 95.

    This UDF split line feed first, and split each line, all line's length are equal to or less then LENGTH.

    Below two formula is equivalant.
    =TextWrap(B1)
    =TextWrap(B1, 95)

    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    10-30-2024
    Location
    Sweden
    MS-Off Ver
    365
    Posts
    3

    Re: Bypass justify

    Hi,

    Thanks, this is a very good solution. Even better than I imagined. I'm also impressed that you responded so quickly, especially when I hadn't seen anyone else have a solution on how to, as an alternative to Justify, spill more than 255 characters.
    I am attaching a pdf of how nice this turned out. Thank you once again.

    Protokoll ST.pdf

    Best regards
    Tim

  6. #6
    Registered User
    Join Date
    11-01-2024
    Location
    Korea
    MS-Off Ver
    M365 64bit v2410
    Posts
    185

    Re: Bypass justify

    Thanks for your reputation.

+ 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. Justify allignment
    By Immortal2014 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-16-2020, 06:29 AM
  2. Excel 2007 : Using Fill Justify
    By ChemistB in forum Excel General
    Replies: 0
    Last Post: 08-14-2009, 11:00 AM
  3. Justify Method
    By ben in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-16-2006, 02:50 PM
  4. Series & Justify?
    By Scorpionk88 in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 08-01-2005, 04:04 PM
  5. Justify right
    By sgk in forum Excel General
    Replies: 0
    Last Post: 04-02-2005, 06:33 AM
  6. [SOLVED] Right Justify List Box Entries
    By Dandog in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-21-2005, 12:06 PM
  7. [SOLVED] text and formula justify??
    By L/P in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-17-2005, 08:06 PM

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