Home |
Search |
Today's Posts |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I made a mistake in what I told you. The statement:
With Sheet2 should be: With Sheets("Sheet2") This is assuming that Sheet2 is the sheet tab text. HTH Otto "Sandy" wrote in message ... Hi Otto! Thanks so much for your response! -- Sandy "Sandy" wrote: 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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
hide, unhide column or row after protect worksheet | Excel Discussion (Misc queries) | |||
Hide/Unhide after protect sheet | Excel Discussion (Misc queries) | |||
VB Code to hide and unhide rows | Excel Discussion (Misc queries) | |||
Code to hide and unhide columns, with certain condition? | Excel Programming | |||
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. | Excel Worksheet Functions |