Trailing White Spaces

rbs

Board Regular
Joined
Oct 6, 2002
Messages
58
Hi Everyone,

I have a query in which I have various fields that I need to specify are a certain number of characters each.

I need to append Trailing White Spaces to the end of each field to make the field the correct number of characters.

Further to this, I need to append Leading zeros to all of the numeric characters to bring them to the correct number of characters.

Can anyone help.

Thanks in advance.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi,

You can do this using an update query. Create a new query in design view and change it to an Update Query (by clicking Query, Update Query). The expression you will need to enter in the 'Update To' will be something like:-

[Table1]![Field1] & Space$(50-Len([Table1]![Field1]))

Obviously you'll need to use your actual table and field name. The 50 refers to the length you want the field to be. The SQL of the query I wrote is:-

UPDATE Table1 SET Table1.Field1 = [Table1]![Field1] & Space$(50-Len([Table1]![Field1]));

<hr>

You can use an update query to append a zero as well. Use something like:-

UPDATE Table1 SET Table1.Field1 = "0" & [Table1]![Field1];
 
Upvote 0
Or you could try something like this.

Format(12345,"0000000")
Format([Field1],"0000000")

HTH,
CT
 
Upvote 0

Forum statistics

Threads
1,221,569
Messages
6,160,557
Members
451,656
Latest member
SBulinski1975

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