LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 355
Default Hide/Unhide in Code; Protect, Unlock, etc.

Hello -

I have code that works, however, I am sure this is not the correct way to do
it. Can anyone show me how this is normally done more efficiently and with
less lines of code?

Locking the sheet and then unlocking certain cells in a range is really
clunky! Additionally, I do use this same range elsewhere in code on another
sheet. How do I write it once and refer to it from different sheets?

Any help will really be appreciated!

Sub UnhideRowsAndUnlockCells()
Sheet2.Unprotect ("pwdGoldieLocks")
Sheet2.Rows("1:250").Locked = False
If Sheet2.Rows("30:36").Hidden = True Then
Sheet2.Rows("30:36").Hidden = False
Else
Sheet2.Rows("30:36").Hidden = False
End If
<snip

Sheet2.Range("D2").Value = "Food"

If Sheet2.cmdFood.Visible = False Then
Sheet2.cmdFood.Visible = True
Else
Sheet2.cmdFood.Visible = True
End If
If Sheet2.cmdFood.Enabled = False Then
Sheet2.cmdFood.Enabled = True
Else
Sheet2.cmdFood.Enabled = True
End If
<snip
Sheet2.Rows("1:250").Locked = True
Sheet2.Range("D8:D16, D23:D27, D29:D31, D33:D42," & _
"D44:D50, D52:D57, D59:D78, D80:D83, D85:D86, D88:D94").Locked = False
Sheet2.Range("D102:D105, D107:D111, D113:D115, D123:D128, D135:D136," & _
"D143:D144, D146, D154:D156").Locked = False
Sheet2.Range("D158:D159, D167:D170, D172:D174," & _
"D176, D178:D179, D187:D189, D191:D197, D212").Locked = False
Sheet2.Range("D214:D218, D221:D230, D237:D240").Locked = False

Sheet2.Protect ("pwdGoldieLocks")

'Sheet21
Sheet21.Unprotect ("pwdGoldieLocks")
Sheet21.Rows("1:250").Locked = False
If Sheet21.Rows("30:34").Hidden = True Then
Sheet21.Rows("30:34").Hidden = False
Else
Sheet21.Rows("30:34").Hidden = False
End If
<snip
If Sheet21.cmdCheckFacilities.Visible = True Then
Sheet21.cmdCheckFacilities.Visible = False
Else
Sheet21.cmdCheckFacilities.Visible = False
End If

Sheet21.Rows("1:250").Locked = True
Sheet21.Protect ("pwdGoldieLocks")
'Sheet17
Sheet17.Unprotect ("pwdGoldieLocks")
Sheet17.Rows("1:250").Locked = False
If Sheet17.Rows("18:21").Hidden = True Then
Sheet17.Rows("18:21").Hidden = False
Else
Sheet17.Rows("18:21").Hidden = False
End If
If Sheet17.Rows("23:57").Hidden = True Then
Sheet17.Rows("23:57").Hidden = False
Else
Sheet17.Rows("23:57").Hidden = False
End If
<snip
Sheet17.Protect ("pwdGoldieLocks")
'Unhide sheets hidden for Facilities
Sheet5.Visible = True
Sheet6.Visible = True
Sheet8.Visible = True
Sheet9.Visible = True
Sheet22.Visible = True
Sheet5.Visible = xlSheetVisible
Sheet6.Visible = xlSheetVisible
Sheet8.Visible = xlSheetVisible
Sheet9.Visible = xlSheetVisible
Sheet22.Visible = xlSheetVisible
End If
--
Sandy
 
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
hide, unhide column or row after protect worksheet tiny[_2_] Excel Discussion (Misc queries) 2 May 14th 09 04:23 PM
Hide/Unhide after protect sheet RKS Excel Discussion (Misc queries) 0 March 21st 08 05:03 AM
VB Code to hide and unhide rows Raj Excel Discussion (Misc queries) 2 February 27th 08 05:58 AM
Code to hide and unhide columns, with certain condition? Frederic Excel Programming 2 June 29th 05 04:23 PM
how do i password protect an .xls file? how do i unlock it for automation. e.g. want to unlock and access a .xls from another .xls macro. Daniel Excel Worksheet Functions 1 June 24th 05 02:59 PM


All times are GMT +1. The time now is 12:00 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"