9tanstaafl9
Well-known Member
- Joined
- Mar 23, 2008
- Messages
- 535
Hi everyone. If someone accidentally (and this has happened) enters a job number followed by a plus sign into the input box, they get a 1004 error, which effectively lets them exit the macro while the sheet is still unprotected.
I can't figure out why this is happening, since I don't unprotect the sheet until after I'm done testing to see if the number is valid. Job numbers could be any positive integer.
And yes, I'm somewhat new to this, so if my code is wasteful or goofy, please tell me what to fix instead of just laughing.
Thanks!
Jennifer
I can't figure out why this is happening, since I don't unprotect the sheet until after I'm done testing to see if the number is valid. Job numbers could be any positive integer.
Code:
Private Sub ChangeJob()
'creates new job, deletes old projections
'tests to see if connected to data first
ActiveWorkbook.Unprotect Password:="ma$terbuilder" 'needed to set visibility
Worksheets("Cost Code Names").Visible = xlSheetVisible
Worksheets("Cost Code Names").Unprotect Password:="ma$terbuilder"
On Error Resume Next
Worksheets("Cost Code Names").Range("b1").QueryTable.Refresh BackgroundQuery:=False
If Err.Number <> 0 Then
MsgBox ("You are not connected to your Master Builder data, try again later.")
Worksheets("Cost Code Names").Protect Password:="ma$terbuilder"
Worksheets("Cost Code Names").Visible = xlVeryHidden
ActiveWorkbook.Protect Password:="ma$terbuilder"
Exit Sub
End If
Dim YesNo As Variant
YesNo = MsgBox("Are you sure you want to create a new job? If you have entered any notes or projections, you should choose NO and save any changes before creating a new job.", vbYesNo + vbCritical + vbDefaultButton2, "NEW JOB")
Select Case YesNo
Case vbYes
Start:
Dim a As Variant
a = Application.InputBox("Enter the Job Number you wish to report on.", "Enter JOB NUMBER.")
On Error Resume Next
If a = "" Then End
If a = False Then End
Dim xx As Variant
xx = a
If Not IsNumeric(xx) Or Val(xx) <> Int(xx) Then
MsgBox "Whole numbers only please."
GoTo Start
End If
ActiveSheet.Unprotect Password:="ma$terbuilder"
ActiveWindow.FreezePanes = False
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
Range("RealJobNumber").Value = a
'alter when adding rows or columns
If Range("d17") = "" Then GoTo WasBlank
Application.Run "RemoveAll"
WasBlank:
Application.Run "Everything" 'processes the job
Case vbNo
End Select
And yes, I'm somewhat new to this, so if my code is wasteful or goofy, please tell me what to fix instead of just laughing.
Thanks!
Jennifer