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??
 

Some videos you may like

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,514
Office Version
  1. 365
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,123
Messages
5,622,870
Members
415,935
Latest member
kes1973

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