Macro to hide sheets if there is no value in cell A2 & below

harry2908

Board Regular
Joined
May 7, 2010
Messages
87
I am not familiar with VBA, i require a macro which would hide sheet if a sheet is empty on the basis of coulmn A
There are about 20-25 sheets in a workbook.
I need a macro which could HIDE the sheets which have no value in cells A2 & below (considering row 1 is a header row)

Appreciate your help...!!!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Put it in standard module.
Code:
[COLOR="Blue"]Sub[/COLOR] HideSheets()

    [COLOR="Blue"]Dim[/COLOR] sh [COLOR="Blue"]As[/COLOR] Worksheet
    
    [COLOR="Blue"]For[/COLOR] [COLOR="Blue"]Each[/COLOR] sh [COLOR="Blue"]In[/COLOR] Sheets
        [COLOR="Blue"]If[/COLOR] sh.Cells(Rows.Count, "A").End(xlUp).Row = 1 [COLOR="Blue"]Then[/COLOR]
            sh.Visible = xlSheetHidden
        [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]If[/COLOR]
    [COLOR="Blue"]Next[/COLOR]

[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,722
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top