Summary

To pad text to an equal length using another character, you can use a formula based on the REPT and LEN functions. In the example shown, a formula is used to append a variable number of asterisks (*) to values in column B so that the final result is always 12 characters in length. The formula in C5 is:

=B5&REPT("*",12-LEN(B5))

Generic formula

=A1&REPT("*",count-LEN(A1))

Explanation 

This formula concatenates the original value in column B to a string of asterisks (*) assembled with the REPT function so that the final result is always 12 characters:

REPT("*",12-LEN(B5))

Inside the REPT function, the text to repeat is provided as a single asterisk ("*"). The number of asterisks needed for each value is determined with with the LEN function in this bit of code here:

12-LEN(B5)

We start with 12, then subtract the length of the text in column B. In cell B5, "Sebastian" is 9 characters, so the result is 3. The formula is evaluated like this:

="Sebastian"&REPT("*",12-LEN(B5))
="Sebastian"&REPT("*",12-9)
="Sebastian"&REPT("*",3)
="Sebastian"&"***"
="Sebastian***"

The results in column C is formatted with a monospaced font (Courier New) to clearly show all strings are the same length.

Dave Bruns Profile Picture

AuthorMicrosoft Most Valuable Professional Award

Dave Bruns

Hi - I'm Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.