Custom Fields with spaces

D

durstbj

Hi,
The easiest way to explain my dilemma is by example. I need a custom
field that is always thirty character spaces long no matter how long
the text is. So for example, lets say the word is PIZZA which is 5
characters, I would need 25 blank spaces afterwards to get to 30
characters in total. Does anybody know what this would look like?
I've tried to use the _ but that doesn't seem to work. Thanks.
 
A

a7n9

Suppose A1 has the text you want to format, then use this formula in B1:
=A1&REPT(CHAR(32),30-LEN(A1))
 
R

Rick Rothstein \(MVP - VB\)

=REPLACE(REPT(" ",30),1,LEN(A1),A1)
Wouldn't

=LEFT(A1&REPT(" ",30),30)

Well, that is the same formula that Dave posted... I posted my formula in
order to provide the OP with a choice in case the user enters more than 30
characters. Your (and Dave's) formula will truncate the entry at 30
characters for entries with more than 30 characters in them (which, I freely
admit, is more than likely what the OP wants for this case) whereas the
formula I posted preserves all of the character typed in (just in case the
OP wants to be able to do that).

Rick
 
H

Harlan Grove

Rick Rothstein (MVP - VB) said:
....
Well, that is the same formula that Dave posted... I posted my formula in
order to provide the OP with a choice in case the user enters more than 30
characters. Your (and Dave's) formula will truncate the entry at 30
characters for entries with more than 30 characters in them (which, I
freely admit, is more than likely what the OP wants for this case) whereas
the formula I posted preserves all of the character typed in (just in case
the OP wants to be able to do that).

Didn't see Dave's response. So how 'bout

=A1&REPT(" ",MAX(0,30-LEN(A1)))

?
 
R

Rick Rothstein \(MVP - VB\)

=REPLACE(REPT(" ",30),1,LEN(A1),A1)
Didn't see Dave's response. So how 'bout

=A1&REPT(" ",MAX(0,30-LEN(A1)))

Okay, that is another way to do it. My guess is that if we keep trying,
there are probably a few other ways to accomplish this. Are you proposing
that your formula is the better one to use for some reason (perhaps, it's
more efficient or faster)?

Rick
 
H

Harlan Grove

Rick Rothstein (MVP - VB) said:
Okay, that is another way to do it. My guess is that if we keep trying,
there are probably a few other ways to accomplish this. Are you proposing
that your formula is the better one to use for some reason (perhaps, it's
more efficient or faster)?

It's shorter.

It may be more efficient, depending on how REPLACE works vs concatenation.
 
R

Rick Rothstein \(MVP - VB\)

=REPLACE(REPT(" ",30),1,LEN(A1),A1)
...

It's shorter.

It may be more efficient, depending on how REPLACE works vs concatenation.

Shorter... OK, I can buy that.

Rick
 
Top