Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 618
Default Unprotect and Protect sheet within macro

Hi John

there's no such thing as "worksheet" - if you use "worksheets" you have to
identify which worksheet you're talking about so that won't help you much ..
try instead (for both the protect & unprotect)

Activesheet.protect Password:="password"


Cheers
julieD


"John F" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Unprotect and Protect sheet within macro

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

Activesheet.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

ActiveSheet.Protect Password:="password"

End Sub

--
Regards,
Tom Ogilvy

"John F" wrote in message
...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Unprotect and Protect sheet within macro

Thanks so much - Works great!!
JFS

"Tom Ogilvy" wrote:

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

Activesheet.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

ActiveSheet.Protect Password:="password"

End Sub

--
Regards,
Tom Ogilvy

"John F" wrote in message
...
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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to protect/unprotect a sheet using a macro with password FredH Excel Discussion (Misc queries) 5 October 23rd 07 04:49 PM
Unprotect and protect sheet in a macro Ola Sigurdh Excel Programming 1 September 28th 04 11:55 PM
Protect/Unprotect Sheet from Macro Nigel[_8_] Excel Programming 1 May 14th 04 05:55 PM
Excel VBA-Protect and unprotect sheet with BVA marfrk Excel Programming 1 May 3rd 04 12:37 PM
VBA code - protect and unprotect a sheet Jeff Excel Programming 2 December 2nd 03 11:44 PM


All times are GMT +1. The time now is 05:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"