I haven't ever dealt with supplying messages when it comes to errors before.
From reading some of the posts it looks like you either let VBA do it or you do it?
In my application I copy data from five workbooks and PasteSpecial it into a target workbook. Apparently the five workbooks have to be open because if even one is closed I get a run-time error '9': Subscript out of range error.
I tried to figure out the error number using a MsgBox and err.number. It says it is zero. I seem to get zero for other errors too (and if I leave that MsgBox line in there it shows a 0 error even if there is not error as far as I can tell).
I don't want the user to get the debug window that takes them into VBA (and that doesn't seem very professional) but I don't really know that should be handling all the errors myself either.
Perhaps it is where I am putting the error handling lines.
Below is some of my code - without the repetitive stuff - in case it helps. Included are the lines where I try to deal with errors - some are commented out as I go back and forth trying one thing or another.
Sub UpdatePeriodXX()
PeriodNum = Application.InputBox("Make sure all the store forecast files are open and then please enter the period number"
If PeriodNum = False Then GoTo 2
'''If Err.Number <> 0 Then
''On Error GoTo 3
''3
'''MsgBox ("Please enter a valid period number."
'''GoTo 2
MsgBox ("Error: " & Err.Number)
'''End If
'Store 1
Workbooks("1forecast.xls"
.Worksheets(PeriodNum).Range("Week1_" & PeriodNum).Copy
Workbooks("PeriodXXInProcess.xls"
.Worksheets("WEEKONE"
.Range("Week1_1"
.PasteSpecial Paste:=xlValues
'Store 2
Workbooks("2forecast.xls"
.Worksheets(PeriodNum).Range("Week1_" & PeriodNum).Copy
Workbooks("PeriodXXInProcess.xls"
.Worksheets("WEEKONE"
.Range("Week1_2"
.PasteSpecial Paste:=xlValues
2
End Sub
Thanks for ideas and suggestions.
Sharon
From reading some of the posts it looks like you either let VBA do it or you do it?
In my application I copy data from five workbooks and PasteSpecial it into a target workbook. Apparently the five workbooks have to be open because if even one is closed I get a run-time error '9': Subscript out of range error.
I tried to figure out the error number using a MsgBox and err.number. It says it is zero. I seem to get zero for other errors too (and if I leave that MsgBox line in there it shows a 0 error even if there is not error as far as I can tell).
I don't want the user to get the debug window that takes them into VBA (and that doesn't seem very professional) but I don't really know that should be handling all the errors myself either.
Perhaps it is where I am putting the error handling lines.
Below is some of my code - without the repetitive stuff - in case it helps. Included are the lines where I try to deal with errors - some are commented out as I go back and forth trying one thing or another.
Sub UpdatePeriodXX()
PeriodNum = Application.InputBox("Make sure all the store forecast files are open and then please enter the period number"
If PeriodNum = False Then GoTo 2
'''If Err.Number <> 0 Then
''On Error GoTo 3
''3
'''MsgBox ("Please enter a valid period number."
'''GoTo 2
MsgBox ("Error: " & Err.Number)
'''End If
'Store 1
Workbooks("1forecast.xls"
Workbooks("PeriodXXInProcess.xls"
'Store 2
Workbooks("2forecast.xls"
Workbooks("PeriodXXInProcess.xls"
2
End Sub
Thanks for ideas and suggestions.
Sharon