View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
KL KL is offline
external usenet poster
 
Posts: 201
Default Please help!!! Using code to password-protect and unprotect...

Hi Hawk,

Try this:

Sub Hide_EmptyColumns()
'To hide columns with no data in rows 10:82
Application.ScreenUpdating = False
Dim col As Range, Pass As String
Pass = "password"
With Sheets("Box")
.Protect Pass
For Each col In .Range("C10:AF82").Columns
col.EntireColumn.Hidden = _
Application.Sum(col) = 0
Next
.Unprotect Pass
End With
Application.ScreenUpdating = True
End Sub


Regards,
KL


"Hawk" wrote in message
ups.com...
With help from this group, I am using the following code to hide empty
columns in my spreadsheet. It works when my sheet is not protected,
however, when I deploy this sheet for use by others it will need to be
password-protected. What can I add to the code to unprotect the sheet
prior to hiding the columns and then re-protect the sheet after the
columns have been hidden? Will my password-protection be preserved?
Please help...

Sub Hide_EmptyColumns()
'To hide columns with no data in rows 10:82


Application.ScreenUpdating = False
With Sheets("Box")
Dim col As Range
For Each col In .Range("C10:AF82").Columns
col.EntireColumn.Hidden = _
Application.Sum(col) = 0

Next
End With
Application.ScreenUpdating = True
End Sub