This is based on another thread, the answer has been given but the code doesn't execute as expected: Specifying multiple sheets in OpenWorkbook
I have a workbook that contains multiple sheets. I want Workbook_Open to execute code that clears cells and inserts specific words into a specific sheet and cell according to the rules specified.
I found that all the code was being executed on the second specified sheet and nothing on the first. So, it cleared data from a list on the VO Areas based on
Then added "Property Reference Guide (Click Arrow to Start)" to cell B2 based on:
It then executed the expected code:
Overall code:
Could someone please tell me why this is happening and how to fix it?
I have a workbook that contains multiple sheets. I want Workbook_Open to execute code that clears cells and inserts specific words into a specific sheet and cell according to the rules specified.
I found that all the code was being executed on the second specified sheet and nothing on the first. So, it cleared data from a list on the VO Areas based on
VBA Code:
Range("C13").Select
Selection.ClearContents
Range("C8").Select
Selection.ClearContents
Range("B2").Select
Selection.ClearContents
Then added "Property Reference Guide (Click Arrow to Start)" to cell B2 based on:
VBA Code:
Range("B2").Value = "'Property Reference Guide (Click Arrow to Start)"
Range("B2").Select
It then executed the expected code:
VBA Code:
ElseIf sh.Name = "VO Areas" Then
sh.Protect UserInterFaceOnly:=True, AllowSorting:=True, AllowFiltering:=True
sh.Range("C4").ClearContents
Range("C4").Value = "'Choose P"
Range("C4").Select
Overall code:
VBA Code:
Private Sub Workbook_Open()
Dim sh As Worksheet
For Each sh In Worksheets
If sh.Name = "Property Numbering" Then
sh.Protect UserInterFaceOnly:=True, AllowSorting:=True, AllowFiltering:=True
'sh.Range("C13,C8,B2").ClearContents
Range("C13").Select
Selection.ClearContents
Range("C8").Select
Selection.ClearContents
Range("B2").Select
Selection.ClearContents
Range("B2").Value = "'Property Reference Guide (Click Arrow to Start)"
Range("B2").Select
ElseIf sh.Name = "VO Areas" Then
sh.Protect UserInterFaceOnly:=True, AllowSorting:=True, AllowFiltering:=True
sh.Range("C4").ClearContents
Range("C4").Value = "'Choose P"
Range("C4").Select
Else
sh.Protect UserInterFaceOnly:=True
End If
Next
End Sub
Could someone please tell me why this is happening and how to fix it?