Padding a word with spaces to fill a cell

点点圈 提交于 2021-01-21 12:12:47

问题


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.


回答1:


Try this:

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

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

enter image description here




回答2:


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




回答3:


I had to right pad the numbers in a cell with 0 to make it maximum 9 characters. All had uneven numbers in the cell. I used the below formula to achieve the result. For me the least characters present in the cell was 3. =LEFT(G41 & REPT("0",6),9)



来源:https://stackoverflow.com/questions/29363823/padding-a-word-with-spaces-to-fill-a-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!