Archive

Posts Tagged ‘VBA’

Unhide all worksheets at same time

Excel 2007 made it easier to unhide sheets, but this macro unhides them all at the same time.  Very quick and easy to use.  I personally attach the user command ‘Ctrl+u’ to unhide all sheets because I use this macro almost daily.  It is also very functional to make files smaller by identifying hidden sheets that aren’t being used and deleting them.

Here’s the VBA code!

Sub Unhide_All_Worksheets()

Application.ScreenUpdating = False

On Error Resume Next

For Each w In Application.Worksheets

w.Visible = True

Next w

For Each z In Application.Charts

z.Visible = True

Next z

End Sub

 

Categories: Macros Tags: , , ,

Are you using Excel 2007 but like 2003 menus?

Here is some code (h/t to JWalk blog) on how to get the Excel 2003 menu, but show in Excel 2007.

Just enter this into any VBA module and run it, it will add to your add-ins toolbar.

Sub MakeOldMenus()
On Error Resume Next
‘ Delete it, if it exists
Application.CommandBars(“Old Menus”).Delete
On Error GoTo 0
‘ Create an old-style toolbar
‘ Set the last argument to False for a more compact menu
Set OldMenu = Application.CommandBars.Add(“Old Menus”, , True)
‘ Copy the controls from Excel’s “Built-in Menus” shortcut menu
With CommandBars(“Built-in Menus”)
.Controls(“&File”).Copy OldMenu
.Controls(“&Edit”).Copy OldMenu
.Controls(“&View”).Copy OldMenu
.Controls(“&Insert”).Copy OldMenu
.Controls(“F&ormat”).Copy OldMenu
.Controls(“&Tools”).Copy OldMenu
.Controls(“&Data”).Copy OldMenu
.Controls(“&Window”).Copy OldMenu
.Controls(“&Help”).Copy OldMenu
End With
‘ Make it visible. It appears in the Add-Ins tab
Application.CommandBars(“Old Menus”).Visible = True

End Sub

Categories: Macros Tags: , , ,

Are you a big fan of pivot tables?

I use pivot tables constantly for data mining.  When becoming comfortable with them, they become very powerful.  I’m not going to get into the detail of how to set them up or what they are used for, you are definitely my target market if you use them.  I’ve had Excel files before that have multiple pivot tables across many tabs.  This piece of VBA code gives you confidence that all pivot tables are refreshed, as this code will go through each pivot table on each tab and refresh accordingly.  This doesn’t take a lot of code, but is very easy to add to your personal workbook (see here).    Here you go…

Sub RefreshAllPivots()
‘Dim is creating the shortcuts for Worksheet and Pivot Table
Dim wks As Worksheet
Dim pt As PivotTable

For Each wks In Worksheets
‘Cycles through each worksheet

For Each pt In wks.PivotTables
‘Cycles through each pivot table

pt.RefreshTable
‘Refreshes the pivot table

Next pt
‘Skips to the next pivot table and refreshes until no more pivots to refresh on that worksheet
Next wks
‘Goes to the next worksheet and starts refreshing until all tabs have been seached and updated

End Sub

Hope this helps!

Categories: Macros, Pivot Tables Tags: ,
Design a site like this with WordPress.com
Get started