VBA code to hide tabs calculated cell value

locker38

New Member
Joined
Mar 7, 2018
Messages
2
I went to a Mr. Excel workshop a few months ago and told me that this board was a great resource. I know excel fairly well however my VBA skills are lacking. I did try to search the site and I found similar or related posts but I couldn’t find exactly what I needed. Any help is greatly appreciated.

I want to run VBA code a single time to hide all tabs that have “HIDE” in cell G1. I am creating a master budget worksheet that will be used for approximately 30 departments. The worksheet has a summary tab, a master data tab and then a tab for each GL account that is used (approximately 200 tabs). I have a drop down list on the first page to select department and then all 200 tabs are updated with formulas that pull from the master data tab. Each department only uses some fraction of the possible GL accounts. I spent countless time last year hiding unused tabs for each department.

Here is a summary of the steps that I would take for each department:


  • Open master template/file
  • Select department on summary tab
  • I will put a formula in cell G1 on each to the 200 GL tabs that will equal hide if that department has no prior budget or actuals for that account
  • Run VBA to hide all tabs with the phrase “HIDE” in cell G1
  • Save and email worksheet to department head
  • Repeat for the next department
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
This script will hide all sheets with "HIDE" in Range("G1")
Not sure about the other things you want and what part if any of this have you already done.

Code:
Sub Hide_Sheets()
'Modified 3-7-18 7:00 PM EST
Dim i As Long
Application.ScreenUpdating = False
    For i = 1 To Sheets.Count
     If Sheets(i).Range("G1").Value = "HIDE" Then Sheets(i).Visible = False
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
If you want a script to enter a formula into a certain range in all sheets then try this:

Code:
Sub Insert_Formula()
'Modified 3-7-18 7:20 PM EST
Dim i As Long
Application.ScreenUpdating = False
    For i = 1 To Sheets.Count
        Sheets(i).Range("G1").Formula = "=B1+B2"
     Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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