Maintaining Constant Number of Characters in a String

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a field (column A) of text data. The value in the cells can be between 2 and 5 characters in length.

In column D, I must maintain the value in column A, however, the text string in column D must be exactly 15 characters long. The extra characters must be spaces.

eg. A1 = "CW", therefor D1 must equal "CW-------------", where "-" are spaces.
A2 = "BOOPY", therefore D2 must equal "BOOPY----------"

Sometimes there is no value at all in column A. In that case, column D equals the value in column B which is a constant 14 characters long. Again, column D must be 15 characters long.

eg A3="", B3="n000.00.00.000", therefore D3 must equal "n000.00.00.000-", where - is a space

So far I have this formula in column D, which so far only determines if A is empty, then substitutes a concatenated value of B + one space when A is empty.

d20=IF(A20="",CONCATENATE(B20,""),A20)

What it doesn't do, and for which I come herer for help, is to assign D a 15 character value based on the value in A.

Thank you in advance to anyone reading and able to help me with this.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Maybe ...

=IF(LEN(A1), A1 & REPT(" ", 15-LEN(A1)), B3 & REPT(" ", 15-LEN(B3)))
 
Upvote 0
Is there only going to be a value in either one of the cells?

If so,

=LEFT(A1&B1&rept(" ",15),15)
 
Upvote 0
Thanks all for your replies ...

SHG, your solution worked wonderfully. Thank you!
 
Upvote 0

Forum statistics

Threads
1,214,665
Messages
6,120,804
Members
448,990
Latest member
rohitsomani

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