View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
John F[_2_] John F[_2_] is offline
external usenet poster
 
Posts: 24
Default Unprotect and Protect sheet within macro

The following causes "Variable Not Defined" message
NOTE: Hide rows macro works great. I can't get the unprotect and protect to
work
if spite of numerous attempts at understanding user group info and the
microsoft help. Obviously a lot to learn yet.
Is part of the problem the positioning of the unprotect statement?
This macro will be used for a number of worksheets/workbooks so I can't have
the statement directly identify the worksheet name (since it is different in
each workbook).


Option Explicit
Sub Hide_Rows()
' Hide_Rows Macro
' January 11, 2005
' From Frank Kabel
' Keyboard Shortcut: NONE

Worksheet.Unprotect Password:="password"

Dim RowNdx As Long
Dim LastRow As Long
Application.ScreenUpdating = False
LastRow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "B").Value = "x" Then
Rows(RowNdx).Hidden = True
End If
Next RowNdx
Application.ScreenUpdating = True

Worksheet.Protect Password:="password"

End Sub
--
John F. Scholten