variable number of leading zeros number as text loop problem

jon78981

New Member
Joined
Jun 26, 2020
Messages
11
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have code which creates a designated numbers of folders eg 3 folders and saves a spreadsheet into the designated filepath. of each folder. The folders name and spreadsheet name is based on cell values in the spreadsheet


However i have come across a problem. The loop coding works fine when the cells are set up to act as numbers. The coding and loop works correctly when just have number as the cell format.
eg 500 501 502
The macro creates the folder correctly named in the folder and spreadsheet is saved into the there correctly named.

However i have case where have to deal with variable number of leading zeros (`0`s) some. folders and spreadsheets should be named for example as 000006 000045 000456 003456 012345
The length is always fixed at 6 digits
when i change the cell format to text the loop naming method doest work the leading zeros are missing off so 000006 becomes 6.

How to solve this??
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I think it would be beneficial for us to see your code and a sample of your data.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0

Forum statistics

Threads
1,215,002
Messages
6,122,652
Members
449,092
Latest member
peppernaut

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