Let’s say you are working with multiple worksheets, and for you, it’s hard to navigate to a sheet using a tab. In this situation, you can use a VBA code to activate any worksheet.
And, to write a VBA code for this you need to use Worksheet.Activate Method. In this post, I’d like to share with you a simple way to write this code to activate or select a worksheet. Before you write this code, you need to understand this method.
In this method, you can specify the worksheet’s name or number which you want to activate. Let’s say you need to activate sheet1, then the code will be:
Or you can use sheet numbers as well.
So the final code will be:
Examples: Activate a Worksheet with VBA
In the real life, you can use this method in different ways. Here are some of them.
1. Activate a Worksheet on Opening
If you want to activate a specific worksheet every time when you open the workbook then you name that VBA code auto_open.
2. Activate a Worksheet and Hide all other
Maybe you want to navigate to a worksheet and hide all the other worksheets from the workbook. You can do this by using the below code.
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Sheet1" Then
ws.Visible = xlSheetHidden
Change the sheet name from the above code to use it further.