Reputation: 781
I was wondering if there was a way to run a VBA script when I open a sheet in the workbook.
For example, I have a workbook called "Inventory" and I want to run an "InitiateInventoryValues" Function when the "View Inventory" sheet is opened.
Can anybody please help me on this?
Upvotes: 6
Views: 36006
Reputation: 14685
Double click the "Workbook" icon in VBE and use this event. It will trigger everytime you activate a different sheet by clicking its tab. If the tab is the one named "View Inventory", your code will run (once) when the sheet is activated:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Sh.Name = "View Inventory" Then
'Do your code
End If
End Sub
Upvotes: 11