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
 
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
 
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:
Back
Top