I am getting an error on this line of code;…
- User
I am getting an error on this line of code; ThisWorkbook.Worksheets("Observe").Range("A2").Select
In this event;
Private Sub Workbook_Open()
ThisWorkbook.Worksheets("Observe").Activate ThisWorkbook.Worksheets("Observe").Range("E1").Value = "SUMMARY" ThisWorkbook.Worksheets("Observe").Range("A2").Select ThisWorkbook.Worksheets("Observe").Range("A1").Calculate
ThisWorkbook.Worksheets("Prem PA").Range("A1").Calculate ThisWorkbook.Worksheets("Prem PA").Range("C2").Value = ""
ThisWorkbook.Worksheets("Prem AA").Range("A1").Calculate ThisWorkbook.Worksheets("Prem AA").Range("C11").Value = ""
ThisWorkbook.Worksheets("Prem CL").Range("A1").Calculate ThisWorkbook.Worksheets("Prem CL").Range("C8").Value = ""
ThisWorkbook.Worksheets("Prem SU").Range("A1").Calculate 'ThisWorkbook.Worksheets("Prem SU").Range("C11").Value = ""
ThisWorkbook.Worksheets("Prem MG").Range("A1").Calculate 'ThisWorkbook.Worksheets("Prem MG").Range("C11").Value = ""
End Sub
... Is there a better way to write this event.
- Assistant
The error you are experiencing is likely due to the fact that the "Observe" worksheet is not currently active when the code tries to select cell A2. It's generally best practice to avoid using the Select method and instead directly reference the cell or range you want to work with. Here's one way you could rewrite the code:
Private Sub Workbook_Open()
code - User
All parts of your code are correct, except .Range(“A2”).Value = “Example Value”. What I want to do here is to Activate the sheet and select A2
- Assistant
If you want to activate the sheet and select cell A2, you can modify that line of code to:
codeWith observeSheet .Range("E1").Value = "SUMMARY" .Activate .Range("A2").Select .Range("A1").Calculate End WithThis will activate the "Observe" sheet and select cell A2 before calculating the value in cell A1.