Posts tagged: all

Select all visible sheets in a workbook

sub select_visible_sheets ()
   Dim ws As Worksheet
   
    For Each ws In Sheets
        If ws.Name <> "SOURCE DATA" And ws.Visible Then ws.Select (False)
    Next
End Sub

Update all pivot tables in a workbook

Option Explicit

Sub RefreshAllPivots()
Dim ws As Worksheet
Dim pt As PivotTable

On Error Resume Next
For Each ws In ActiveWorkbook.Worksheets
   For Each pt In ws.PivotTables
     pt.RefreshTable
   Next
Next
End Sub

Hide All But One Sheet

Hide All But One Sheet

Loop through all sheets in a Workbook and hide all but Sheet1. Excel will not allow all sheets hidden.

Sub HideAllButOneSheet()

'We must leave at least one Sheet visible

Dim wsSheet As Worksheet

    For Each wsSheet In Worksheets

       wsSheet.Visible = wsSheet.Name = "Sheet1"

    Next wsSheet

End Sub

Clear content for all unprotected cells

Clear the content (empty) all unprotected cells in a protected sheet!
This comes in very handy when you want to be able to clear all input fields in a template you have built and protected.

Note: make sure you only run this macro if your sheet is protected, otherwise it clears everything..

Sub ClearSheet()
On Error Resume Next
    ActiveSheet.UsedRange.Value = vbNullString
On Error GoTo 0
End Sub