Make set length of text value?

brianburen

New Member
Joined
Aug 24, 2010
Messages
44
I have a userform that shows the results of many values in 20 text strings

such as:

textlabel1= "firstname1 & " " & lastname1 & " " & housenumber1 & " " & street name1"

textlabel2= "firstname2 & " " & lastname2 & " " & housenumber2 & " " & street name2"

I want to set the text lengths of ... to be x amount letters always, so on the form it all lines up nicely


How do i format the length of the text to be 6 letters even if it is a 4 letter street and the extra 2 letters be spaces?

I tried:

firstname1=Format(ws.range("A1").Text, "XXXXXX")

but it doesnt work
 
Last edited:

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
brianburen,

Something like this?
Code:
    firstname1 = ws.Range("A1").Text
    If Len(firstname1) < 6 Then firstname1 = firstname1 & String(6 - Len(firstname1), " ")
 
Upvote 0
So far neither suggestion is working, but I am not getting any errors either.

I'm gonna fiddle with it a while....
 
Upvote 0
on further evaluation it seems both of these suggestions ARE in fact working, but the width of the " " space is not equal to the space of an "A" or "5".
Is there a font that has equal horizontal spacing for spaces, caps letters, and numbers?
 
Upvote 0
on further evaluation it seems both of these suggestions ARE in fact working, but the width of the " " space is not equal to the space of an "A" or "5".
Is there a font that has equal horizontal spacing for spaces, caps letters, and numbers?

I guess I should note that all letters are in CAPS.

so if i replace the " " with "X", both suggestions work, except I dont want the X's
 
Upvote 0
brianburen,

You could use a tab character instead of spaces:
Code:
firstname1 = ws.Range("A1").Text & Chr(9)

If the alternate font route is what you'd prefer, then Consolas is a uniform size font you could try.
 
Upvote 0
brianburen,

You could use a tab character instead of spaces:
Code:
firstname1 = ws.Range("A1").Text & Chr(9)

If the alternate font route is what you'd prefer, then Consolas is a uniform size font you could try.

Ok it puts a set amount of characters after the text. how can i make it determine if say the firstname1 was only 4 characters, to add 5 characters
and if firstname2 was only 7 characters, it would add 2?
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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