Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Padding a word with spaces to fill a cell

Is it possible to pad a cell with spaces to ensure that it is the correct length?

Here's an example with * representing spaces.

Input    Output
-----    ------
red      red**
blue     blue*

The words are padded with spaces to ensure the cell content is 5 characters long.

like image 378
Terry Avatar asked Mar 31 '15 08:03

Terry


People also ask

How do you add padding to a cell in Excel?

Right-click on one of the selected cells and choose "Format Cells" from the context menu. In the "Format Cells" dialog box, click on the tab for "Alignment." In the "Cell Margins" section, enter the amount of space that you want around the cells. You can enter different values for top, bottom, left, and right.

Is there a pad function in Excel?

Pad for display onlyThe TEXT function can apply number formats of any kind, including currency, date, percentage, etc. By applying a number format like "00", "000", "0000", you can "pad" numbers with as many zeros as you like. Zeros will only be added where needed...


2 Answers

Try this:

=LEFT(A1&"*****",5)

We are adding lots of stars(*) then just cutting from left 5 characters.

enter image description here

like image 145
zx8754 Avatar answered Oct 20 '22 21:10

zx8754


As per suggested comment:

=LEFT(A1 & REPT("*",5),5)

original:

=A1 & REPT("*",5-len(A1))

main advantage being that you can pass the length and the pad character as a cell reference, and easily update

like image 29
user3616725 Avatar answered Oct 20 '22 20:10

user3616725