Livin404
Well-known Member
- Joined
- Jan 7, 2019
- Messages
- 743
- Office Version
- 365
- 2019
- Platform
- Windows
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.
Thank you,
Thank you,
VBA Code:
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