Auto Column Width Macro/Protected vs. Unprotected Worksheet

Mei_Mienzi

New Member
Joined
Apr 11, 2016
Messages
20
Hello:

I have a spread sheet that I have made a macro for. That macro is a follows:

Private Sub Worksheet_Change(ByVal Target As Range)
Columns().AutoFit
End Sub

The two boxes above the macro are:
(Left Box) Worksheet (Right Box) Change

The macro works just fine, BUT I do have a problem. In order for the macro to run the worksheet has to be "unprotected." Is there any way to get this macro to run with the worksheet "protected?" If I leave it unprotected someone is going to louse it up. If left as is, in "protected" status, the macro will not run.

Any resolution?

Thanks,
 

Some videos you may like

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
Welcome to the Board!

You can Unprotect/Reprotect in your code:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  ActiveSheet.Unprotect "PasswordHere"  
    Columns().AutoFit
  ActiveSheet.Protect "PasswordHere"
End Sub
HTH
 

Watch MrExcel Video

Forum statistics

Threads
1,098,875
Messages
5,465,220
Members
406,419
Latest member
ldp124

This Week's Hot Topics

Top