Protection kills macro

E

excelhurtsme

I have an event macro on worksheet, works beautifully when worksheet is
unprotected but will not when the sheet is protected. Gives me "unable to set
the ColumnWidth property of the Range Class" error. The event Macro looks
like this

Private Sub Worksheet_SelectionChange (ByVal Target As Range)
Dim myRng As Range

Set myRng = Me.Range("A10:A16,A22:A33,A37:A46,G22:G33").EntireColumn

If Target.Count > 1 Then Exit Sub

'reset all those column widths
myRng.ColumnWidth = 7
If Intersect(Target, myRng) Is Nothing Then
'do nothing
Else
Target.EntireColumn.ColumnWidth = 20
End If
End Sub
 
J

Jim Thomlinson

Add
me.Unprotect "MyPassWord"
at the beginning and
me.protect "MyPassWord"
at the end.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top