Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

Text function for trailing spaces

If I have a  cell that contains something less than 12 characters , how can I get spaces added on end where total length is 12 characters in field?
0
cebu1014
Asked:
cebu1014
  • 2
  • 2
2 Solutions
 
Shanan212Commented:
=IF(LEN(A2)<12,A2&REPT(" ",12-LEN(A2)),A2)

Considering the cell is A2
0
 
Patrick MatthewsCommented:
No need for the IF, really :)

=LEFT(A2&REPT(" ",12),12)
0
 
Shanan212Commented:
I see what you did there! :)
0
 
Patrick MatthewsCommented:
cebu1014,

Please note that my formula might mishandle entries that are already >12 characters long.  For example, if the original entry is 17 characters long, my formula will truncate at the 12th character, while Shanan212's formula will return all 17 characters (and not add any trailing spaces).

Only you know whether or not there would ever be any initial data with >12 characters, and what should happen in that event.

:)

Patrick
0
 
cebu1014Author Commented:
It will be 12 characters max. Never longer.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now