Where the cursor is flashing, add the code shown below.
To make the Excel VBA code run automatically, we’ll use the Worksheet_Change event, on the Orders sheet. Now that you’ve seen the syntax, you can close the workbook where you recorded the show/hide macro, without saving it, and return to the Orders workbook in Excel. This shows that we can set the sheet’s Visible property to True or False, to show or hide the sheet. In the modules for your new workbook, you should find the recorded code, that looks similar to the code shown below. Turn off the macro recorder, and press Alt+F11, to open the Excel Visual Basic Editor. In the Unhide dialog box, click on the ExportForm sheet name, and click OK. To see the sheet again, click on the Orders sheet tab, and click Unhide. Then, right click on the ExportForm sheet tab, and click Hide. To see what the code should look like, you can turn on the Excel macro recorder, store the macro in a new workbook, and click OK. We’ll be adding some Excel VBA code to hide and unhide the ExportForm sheet. On the Orders sheet, the Country drop down list is created with Excel data validation. If Canada is selected, we need to print the ExportForm sheet, as well as the Orders sheet. This workbook has an order sheet, and there is a country selector at the top of the sheet. In this example we’ll hide Excel sheet when cell changes. Instead of manually hiding or showing the sheets, you can use Excel VBA to automatically hide or show them. In an Excel workbook, you might have some sheets that you don’t need to see all the time.