Q:

Autofit columns error when running in protected Sheets

When I'm execute the code its show [ Run-time error '1004': AutoFit method of Range class failed ] in protected sheet  
Columns("D:DD").AutoFit

Can you guys explain to me why? and how to solve it.

A:

Enabling UserInterfaceOnly when you set your password will allow you to modify the worksheet using the VBA without having to unprotect the worksheet.

Worksheets("Sheet1").Protect Password:="", UserInterfaceOnly:=True

