Hi all,
I'm having an issue whereby when protecting a sheet my macro (responsible for highlighting a cell with a colour when a word limit is exceeded at 200, 350 and 500, each within a separate column) results in a "Run-time-error 1004"
The debug highlights this section of the code:
The full code is here:
The macro works without any issues when the sheet is unprotected, the cells the macro is responsible for are UNPROTECTED as data will be copy and pasted in.
I've read some posts re: allowing the VBA code to unprotect the sheet before running the macro but this seemed to be related to locked cells.
Do I have to apply the same sort of logic to my code? And if so what would I need to add?
Thanks in advance.
I'm having an issue whereby when protecting a sheet my macro (responsible for highlighting a cell with a colour when a word limit is exceeded at 200, 350 and 500, each within a separate column) results in a "Run-time-error 1004"
The debug highlights this section of the code:
The full code is here:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column >= 24 And Target.Column <= 26 Then
Dim txt As String
Dim lim As Long
txt = ""
Select Case Target.Column
Case 24
lim = 200
If Len(Target.Value) > lim Then
Target.Interior.Color = 65535
txt = txt & vbCrLf & Target.Address(0, 0)
End If
Case 25
lim = 350
If Len(Target.Value) > lim Then
Target.Interior.Color = 65535
txt = txt & vbCrLf & Target.Address(0, 0)
End If
Case 26
lim = 500
If Len(Target.Value) > lim Then
Target.Interior.Color = 65535
txt = txt & vbCrLf & Target.Address(0, 0)
End If
End Select
If txt <> "" Then MsgBox "Cell exceeds character limit of " & CStr(lim) & vbCrLf & txt
End If
End Sub
The macro works without any issues when the sheet is unprotected, the cells the macro is responsible for are UNPROTECTED as data will be copy and pasted in.
I've read some posts re: allowing the VBA code to unprotect the sheet before running the macro but this seemed to be related to locked cells.
Do I have to apply the same sort of logic to my code? And if so what would I need to add?
Thanks in advance.