When there is an error, I want to go back to my userform and change the information entered on the form and re pass it into the macro and then continue from: If Len(Dir(sFilePath & newfol, vbDirectory)) = 0…
If Len(Dir(sFilePath & newfol, vbDirectory)) = 0 Then
MkDir sFilePath & newfol & "\"
On Error GoTo UserForm1
Else
MsgBox ("Folder already exists please re enter new folder name")
'End
UserForm1.Show
MoveAndSave_Reports
End If
The above give me an error message: Compile error: Label not defined at “On Error GoTO UserForm1”
When you use an “On Error GoTo” statement, you’re telling the program that when it hits an error, skip to a specific line in the current procedure. For example:
In this example, when the code hits an error (after my “On Error” statement), it will stop what it’s doing and begin executing code at the ErrorHandler label (it’s a label because of the colon at the end). Running this code, you would never see the message box saying x = infinity. Once it hits the error by trying to divide by zero, it will jump down to the ErrorHandler label and give me a message saying I can’t divide by zero.
Chip Pearson has a good introduction to basic error handling here.