Converting and Zero Fill Fields

Rocky0201

Active Member
Joined
Aug 20, 2009
Messages
278
Hi Folks...

I have a few fields that I need to convert in VBA.

Location ID Field - This is a numeric value 1 to 4 characters in length. I need to convert to Text, Right Justify and zero fill to 4 characters. ex: 1 needs to be 0001, 0 needs to be 0000, 22 needs to be 0022.

Zip Code Field - This ia a Zipcode field in my spreadsheet. I need to right justfy and fill with zeros. ex: 1234 needs to be 01234.

Date field - This is formated as mm/dd/yyyy. I need to convert this to the sequence number, right justify, zero fill. ex: 08/01/2011 needs to be Text 40756.

Time Field - This is formated as HH:MM AM or PM. I need to convert this to 24 hour clock.

Any help would greatly be appreciated.

Thanks in advance.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I guess you are looking for something like these...

Location ID Field - This is a numeric value 1 to 4 characters in length. I need to convert to Text, Right Justify and zero fill to 4 characters. ex: 1 needs to be 0001, 0 needs to be 0000, 22 needs to be 0022.
LocationID = Format(OriginalLocationID, "0000")


Zip Code Field - This ia a Zipcode field in my spreadsheet. I need to right justfy and fill with zeros. ex: 1234 needs to be 01234.
ZipCode = Format(OriginalZipCode, "00000")


Date field - This is formated as mm/dd/yyyy. I need to convert this to the sequence number, right justify, zero fill. ex: 08/01/2011 needs to be Text 40756.
DateField = CLng(OriginalDateField)


Time Field - This is formated as HH:MM AM or PM. I need to convert this to 24 hour clock.
TimeField = Format(OriginalTimeField, "hh:mm")
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

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