S
Sandy
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
16, D23
27, D29
31, D33
42," & _
"D44
50, D52
57, D59
78, D80
83, D85
86, D88
94").Locked = False
Sheet2.Range("D102
105, D107
111, D113
115, D123
128, D135
136," & _
"D143
144, D146, D154
156").Locked = False
Sheet2.Range("D158
159, D167
170, D172
174," & _
"D176, D178
179, D187
189, D191
197, D212").Locked = False
Sheet2.Range("D214
218, D221
230, D237
240").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
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
"D44
Sheet2.Range("D102
"D143
Sheet2.Range("D158
"D176, D178
Sheet2.Range("D214
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