Wednesday, 16 December 2020

How to Hide and Unhide Sheets in Excel VBA

 



In this blog post, you will learn about how to hide and unhide sheets in Excel VBA.


In Excel, we can hide and unhide sheets by right-clicking on sheet tabs and select the option for hiding and unhide sheets.


But in this post, you will learn about how to hide and unhide sheets in Excel VBA.


See in the below image, there are some sheets:-




Now with the help of VBA, we will hide and unhide one sheet from the above sheets.



So for that go to the Developer tab and click on the Visual basic tab.


Go to the insert tab and click on the module.

Write down the below VBA macro on the module and press “F8” again and again until “End Sub” to execute code step by step.


Sub Hide_Unhide_Sheets()

Sheets("Main").Visible = False

Sheets("Main").Visible = True

End Sub



In this VBA macro:-

False = Hide Sheets

True= Unhide Sheets


Here we will use sheet “Main” for hiding and unhide with the help of VBA macro. 


Now we will run the VBA code and press “F8” to execute the code step by step. 




Image -01


See that when we execute our first line of VBA code, our sheet “Main” is hiding now.



Image - 02

Now press “F8” again to execute the second line of macro code and see the result in the below image.


Our hidden sheet is appearing again in the sheet bar at the bottom.



Image -03

I hope you find this tutorial useful.

Please feel free to put your comments and suggestion in the comment box below.


Regards

Narendra


Related Posts


How to Change Sheet Tab Color in Excel VBA

How to Change Font Color in Excel VBA

How to Change or Rename the Sheet Name in Excel VBA

How to Move Sheets in Excel VBA

Easiest Way to Copy and Paste Data in Excel VBA

How to Change the Background Color in Excel VBA


No comments:

Post a Comment

Featured post

Pivot Tables