I have used this piece of (crap) code for over 2 years then suddenly today it’s stopped working. When I debug the code when it calls
Sheets("All Trans").Unprotect
The macro just seems to stop working – I haven’t done any Error Handling sadly. The sheet “All Trans” exists no problem – nothing has change – completely confused. Here is the sull subroutine:
Sub add_entry()
If [all_fields].Value Then
res = MsgBox("Method: " & Range("New_Entry").Cells(1, 3) & Chr(13) & "To: " & Range("New_Entry").Cells(1, 4) & Chr(13) & "Amount: " & Format(Range("New_Entry").Cells(1, 5), "#,##0") & Chr(13) & "User: " & Range("New_Entry").Cells(1, 6) & Chr(13) & "Notes: " & Range("New_Entry").Cells(1, 7), vbOKCancel, "New Entry")
If res = 1 Then
Sheets("All Trans").Unprotect
Range("New_Entry").Copy
With Sheets("All Trans")
.AutoFilterMode = FALSE
lastRow = .Range("C" & .Rows.Count).End(xlUp).Row
.Cells(lastRow + 1, 1).EntireRow.PasteSpecial xlValues
End With
Sheets("All Trans").Protect
Application.CutCopyMode = FALSE
' [Method].ClearContents
'[To_Whom].ClearContents
[Amount].ClearContents
' [User].ClearContents
[Notes].ClearContents
Sheets("Input").Activate
Range("G4").Select
Else
MsgBox "Try Again!"
End If
Else
MsgBox "Please enter all fields"
End If
End Sub
I have tried renaming the sheet etc to no avail.
What do you mean by “it’s stopped working”? It does nothing, throws an error or something else?
Do you have more than one Excel file open? The code implicitly is looking for the sheet in the Active Workbook, so if there’s more than one file open and the wrong workbook is active, it could cause an issue. The actual error message would be helpful in narrowing down possibilities.