Add Number of Spaces to String Using a Formula

turtlepokerman

New Member
Joined
Jun 18, 2012
Messages
28
Hello,

I am trying to create a formula that adds spaces so that the string equals a certain number of characters.

Orange_12 (x1 spaces)
Apple__13 (x2 spaces)
Jam____14 (x4 spaces)

*Where underscore represents a space

Is there anyway that I could multiply a quantity of spaces with the concatenate function? If the Fruit Type is in cell A1 and the Quantity is in cell B1. The number of spaces will be shown in cell C1. The output should show the complete text in cell D1.

All help is appreciated.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
[SOLVED] Add Number of Spaces to String Using a Formula

Figured it out.

I need to use the REPT() Function

=REPT(" ",numbers of times to repeat)
 
Upvote 0
You don't need to show the number of spaces separately (although you can, if you otherwise have a need for it). The REPT function (why not "REPEAT" I have no idea) will do it for you:
Code:
=A1 & REPT(" ",max(0, 9 - LEN(A1) - LEN(B1))) & TEXT(B1,"#")

You might want to increase the total length of the strings, to allow for, say, pineapple
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,466
Members
449,086
Latest member
kwindels

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top