+ Reply to Thread
Results 1 to 10 of 10

Formula for a fixed number of characters allowed in a cell

Hybrid View

  1. #1
    Registered User
    Join Date
    05-19-2015
    Location
    Peru
    MS-Off Ver
    2010
    Posts
    9

    Formula for a fixed number of characters allowed in a cell

    Let's say I have first column where I will enter the quantity. In the second column I want the formula to automatically add spaces (depending on how many i want) after the quantity I inputted in the first column.

    For example, I want the second column to always give me a fixed 5 character long.
    So if I enter say 10 in the first column, the second column should give me 10 with three spaces after.
    If I enter say 449 in the first column, the second column should give me 449 with two spaces after to complete my required 5 character length.

    What's the formula for that?

  2. #2
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Microsoft® Excel® for Microsoft 365 MSO (Version 2503 Build 16.0.18604.20000) 64-bit
    Posts
    3,992

    Re: Formula for a fixed number of characters allowed in a cell

    Use below formula

    =5-LEN(A2)&" "&"with two spaces after"

  3. #3
    Valued Forum Contributor
    Join Date
    04-12-2012
    Location
    India
    MS-Off Ver
    Excel 2007, 2010, 2013, 2016, 2019, Office 365, Google Spreadhsheet
    Posts
    640

    Re: Formula for a fixed number of characters allowed in a cell

    Quote Originally Posted by shukla.ankur281190 View Post
    Use below formula

    =5-LEN(A2)&" "&"with two spaces after"
    You are doing minus from 5 to length of formula and then adding the text saying "with two spaces after" whereas OP is saying, OP need the second columns to always give a fixed 5 character long. Let me know If my understanding is wrong.
    Thanks,
    Anil Dhawan


    Click *Add Reputation to say "Thanks" and don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved) if you are satisfied.

    Don't stop when you are tired. STOP when you are done!

  4. #4
    Registered User
    Join Date
    05-19-2015
    Location
    Peru
    MS-Off Ver
    2010
    Posts
    9

    Re: Formula for a fixed number of characters allowed in a cell

    hi shukla, let me rephrase my requirement.

    For example, I want the second column to always give me a fixed 5 character long.
    So if I enter say 10 in the first column, the second column should give me 10XXX
    If I enter say 449 in the first column, the second column should give me 449XX to complete my required 5 character length.

  5. #5
    Valued Forum Contributor
    Join Date
    04-12-2012
    Location
    India
    MS-Off Ver
    Excel 2007, 2010, 2013, 2016, 2019, Office 365, Google Spreadhsheet
    Posts
    640

    Re: Formula for a fixed number of characters allowed in a cell

    Quote Originally Posted by sapfanatic.com View Post
    hi shukla, let me rephrase my requirement.

    For example, I want the second column to always give me a fixed 5 character long.
    So if I enter say 10 in the first column, the second column should give me 10XXX
    If I enter say 449 in the first column, the second column should give me 449XX to complete my required 5 character length.
    You can use the formula given in post 4 and replace space with X.

    Formula: copy to clipboard
    =LEFT(A2&REPT("X",5),5)



    Cheers!!!
    Anil Dhawan

  6. #6
    Valued Forum Contributor
    Join Date
    04-12-2012
    Location
    India
    MS-Off Ver
    Excel 2007, 2010, 2013, 2016, 2019, Office 365, Google Spreadhsheet
    Posts
    640

    Re: Formula for a fixed number of characters allowed in a cell

    Hi Sapfanatic.com,

    You can use the following function to get the fixed 5 character long text.

    Formula: copy to clipboard
    =LEFT(A2&REPT(" ",5),5)


    Let me know if it solve your requirement.


    Cheers!!!
    Anil Dhawan

  7. #7
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Microsoft® Excel® for Microsoft 365 MSO (Version 2503 Build 16.0.18604.20000) 64-bit
    Posts
    3,992

    Re: Formula for a fixed number of characters allowed in a cell

    hope this will give what you want.

    =A2&REPT("X",5-LEN(A2))

  8. #8
    Registered User
    Join Date
    05-19-2015
    Location
    Peru
    MS-Off Ver
    2010
    Posts
    9

    Re: Formula for a fixed number of characters allowed in a cell

    adhawan and shukla, it works. thank you very much cheers!

  9. #9
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,937

    Re: Formula for a fixed number of characters allowed in a cell

    Try
    =text(a1,"00000")
    or
    =a1&iferror(rept("x",5-len(a1)),"")
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  10. #10
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: Formula for a fixed number of characters allowed in a cell

    Try this
    =IF(LEN(A1)<5,A1&REPT(" ",5-LEN(A1)),A1)

+ 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. Increase the number of characters allowed in a post
    By Tony Valko in forum Suggestions for Improvement
    Replies: 9
    Last Post: 11-22-2013, 12:44 PM
  2. [SOLVED] VBA to check a cell based on a set of allowed characters
    By trueimage in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-20-2013, 03:10 PM
  3. Fill the Cell with Zeros upto a fixed number of characters
    By hsmeet in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-15-2008, 10:24 PM
  4. [SOLVED] How can i specify a cell to have a fixed number of characters
    By john dunford in forum Excel General
    Replies: 1
    Last Post: 01-30-2006, 06:10 PM
  5. a way to limit the characters allowed in a cell?
    By EmRit24 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-29-2005, 05:06 PM

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