- Jan 7, 2019
- Office Version
I trying to have my columns and rows adjust automatically while the sheet is protected. There is no password. I got it to work no problem while the worksheet is unprotected. I added Sheets ("Xman") at the begging and end of VBA but it made no difference. I'm hoping it is just a minor correction.
Option Explicit Sub AutoFitAll() Sheets("XMan").Unprotect Application.ScreenUpdating = False Dim wkSt As String Dim wkBk As Worksheet wkSt = ActiveSheet.Name For Each wkBk In ActiveWorkbook.Worksheets On Error Resume Next wkBk.Activate Cells.EntireColumn.AutoFit Cells.EntireRow.AutoFit Next wkBk Sheets(wkSt).Select Application.ScreenUpdating = True Sheets("XMan").Protect End Sub