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("D816, D2327, D2931, D3342," & _
"D4450, D5257, D5978, D8083, D8586, D8894").Locked = False
Sheet2.Range("D102105, D107111, D113115, D123128, D135136," & _
"D143144, D146, D154156").Locked = False
Sheet2.Range("D158159, D167170, D172174," & _
"D176, D178179, D187189, D191197, D212").Locked = False
Sheet2.Range("D214218, D221230, D237240").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("D816, D2327, D2931, D3342," & _
"D4450, D5257, D5978, D8083, D8586, D8894").Locked = False
Sheet2.Range("D102105, D107111, D113115, D123128, D135136," & _
"D143144, D146, D154156").Locked = False
Sheet2.Range("D158159, D167170, D172174," & _
"D176, D178179, D187189, D191197, D212").Locked = False
Sheet2.Range("D214218, D221230, D237240").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