Automaic Folder Numbering

  • Thread starter David Shoemaker
  • Start date
D

David Shoemaker

This is a line of code that i use to create folders on my computer with what
ever value B3 is, now what i would like to do is by clicking a button have it
look under a certain folder and audomaticlly enter the next 5 digit number
and create a folder with that number and put it into a cell in my worksheet
like this - 10001, 10002, 10003, etc......

MkDir "C:\\Globe Photo Engraving\Jobs\" & Range("B3").Value
 
B

Bernie Deitrick

David,

I have assumed the sheet name is Sheet1 - enter the starting number in cell B3 there, and run this
macro:

Sub CreateFolder()
Dim MyFilePath As String
Dim FolderC As Integer

MyFilePath = "C:\Globe Photo Engraving\Jobs\"
FolderC = Worksheets("Sheet1").Range("B3").Value
On Error GoTo FolderExists '<< in case folder exists
TryAgain:
MkDir MyFilePath & FolderC '<< create folder
Worksheets("Sheet1").Range("B3").Value = FolderC + 1
Msgbox "I just created the folder " & MyFilePath & FolderC
Exit Sub
FolderExists:
FolderC = FolderC + 1
Resume TryAgain
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top