out of range error, Excel VB

Joined
Mar 22, 2009
Messages
3
Reaction score
0
The following Macro is meant to search for a folder and if it does not exist then create it. It was working and now that i have changed something i get an "out of range" error on line 5 (DPT =). The cell reference is correct. Has anyone got any ideas?

Code:
Sub createDPT1()
Dim sDir As String
Dim DPT1 As String
sDir = "C:\Rosters 1.0\Rosters"
DPT1 = Worksheets("Roster W1 D1").Range("B3").Value
On Error GoTo ErrNotExist
			ChDir (sDir & "\" & DPT1)
			Exit Sub
ErrNotExist:
			MkDir sDir & "\" & DPT1
End Sub
Jason
 
Joined
Jul 3, 2008
Messages
407
Reaction score
0
Typo m8
DPT1 = Worksheets("Roster W1 D1").Range("B3").Value
Should be
DPT1 = Worksheet("Roster W1 D1").Range("B3").Value

Similar but 2 different objects.
When in Excel and viewing your code... press F2 to open the object viewer... lists every function available and from there you can do your stuff :D
 
Joined
Mar 22, 2009
Messages
3
Reaction score
0
Latest update, with the code as it already was written actually works and creates the folder BUT then also returns the error. how do i make the error not happen so that the rest of the other macros can get their jobs done?
 
Last edited:

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