How do I format/pad a number to have at least 5 digits?

kakiebos

Board Regular
Joined
Jun 10, 2018
Messages
62
I'm working on a macro which involves generating a filename and saving an excel sheet as pdf with that name.
I was able to generate target folder name as follows.

user_name [/FONT][/COLOR]= Environ$("UserName")
file_dir
="C:\Users"& user_name &"\Documents\Jobs"</code>The file name is created as follows.

<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Job_No = Site &"SV"& num_from_cell
PDF
= Job_No &".pdf"
file_path
= file_dir & PDF</code>Currently the above code returns MWSV234.pdf. I want it to be MWSV00234.pdf. num_from_cell comes from one of the cells in excel sheet.
In short, I want to left pad <code style="margin: 0px; padding: 1px 5px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; vertical-align: baseline; box-sizing: inherit; background-color: rgb(239, 240, 241); white-space: pre-wrap;">num_from_cell</code> to 5 digits. Could you please tell me how?
 
Last edited by a moderator:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,303
Office Version
  1. 365
Platform
  1. Windows
Cross posted

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.

Please supply all links
Thanks
 

kakiebos

Board Regular
Joined
Jun 10, 2018
Messages
62
Sorry. I posted the same question in another forum and just copied my question from there to this forum. I do not know how to link it to this thread.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
63,315
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Sorry. I posted the same question in another forum and just copied my question from there to this forum. I do not know how to link it to this thread.
Simply go to the other thread, highlight and copy the entire URL, and then paste it in a reply here. The board should automatically turn that URL in a link for you (you do not need to do anything special with it).

Some advice too. When posting a question, pick a forum to post it to, and then give it some time before posting the question on other forums. You don't just want to post the same question on multiple forums right away.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
63,315
Office Version
  1. 365
Platform
  1. Windows
It also looks like you posted it twice on this forum. Please do not do that. Note that sometimes posts from new users require Moderator approval before you can see them on the public forums. When this happens, you should see a message to that effect when you try to post it. Please be patient and do not attempt to post the question again.

I am going to merge the two threads together.
 
Last edited:
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,305
Messages
5,836,534
Members
430,437
Latest member
Emilycr

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
Top