+ Reply to Thread
Results 1 to 6 of 6

Adding Spaces to Text to Hack Center Align

  1. #1
    Forum Contributor
    Join Date
    12-09-2015
    Location
    Virginia, USA
    MS-Off Ver
    2007
    Posts
    123

    Adding Spaces to Text to Hack Center Align

    I was wondering if anyone knows a formula that would look at the length of a word and add spaces to center the word over 10 available character positions. For example, if I have a word that is 8 letters long, I need the formula to add one space before the word to have centered. A 3 letter word would need three spaces, and a 4 letter word would also need three.


    |NATIONAL|
    |||DOG||||
    |||HELP|||

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,764

    Re: Adding Spaces to Text to Hack Center Align

    It's not hard to do this but it may not result in what you want. Most fonts are proportional fonts, which means every character, including space, has a different width. So you can add spaces but it may not result in the word being centered.

    Why don't you just use formatting to center it, instead of adding spaces?

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


    This formula addresses an odd number by truncating, as you did with your example of DOG. It should have 3.5 spaces so it uses 3.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Adding Spaces to Text to Hack Center Align

    This will add the padding to the right as well.

    =LEFT(REPT(" ",INT((10-LEN(A1))/2))&A1&REPT(" ",10),10)

    Also interested to understand why centering the cell will not suffice
    Cheers
    Andy
    www.andypope.info

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,764

    Re: Adding Spaces to Text to Hack Center Align

    I couldn't figure out why padding to the right would be needed if the intent is to make it look centered within a 10-character width.

  5. #5
    Forum Contributor
    Join Date
    12-09-2015
    Location
    Virginia, USA
    MS-Off Ver
    2007
    Posts
    123

    Re: Adding Spaces to Text to Hack Center Align

    This worked perfecty. Thank you!

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,764

    Re: Adding Spaces to Text to Hack Center Align

    Thanks for the rep!

    If your question has been answered please mark your thread as "Solved" so that members will know by looking at the thread title that your problem is solved. Go to the menu immediately above your first post to the thread and click on Thread Tools. From the dropdown menu select "Mark this thread as solved..."

+ 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] Why wouldn't I be to Center Align?
    By LAPIII in forum Excel General
    Replies: 8
    Last Post: 05-23-2018, 09:18 AM
  2. Center Align text across different rows (alternative to merging)
    By Eliamme in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-11-2017, 07:03 AM
  3. [SOLVED] Help request to align the picture center in web layout
    By mso3 in forum Word Formatting & General
    Replies: 4
    Last Post: 10-15-2015, 09:59 AM
  4. [SOLVED] Align a date in center
    By mukeshbaviskar in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-28-2013, 07:18 AM
  5. Center Align Image
    By shapper in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-20-2008, 04:52 AM
  6. Align to the left or to the right (or center)
    By kaokao1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-05-2006, 11:09 PM
  7. [SOLVED] Center Align
    By John 3:16 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-15-2005, 05:10 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