Excel Guides

Selecting All Visible Worksheets in a Macro in Excel

There are a few different ways that you can select all visible worksheets in a macro in Excel. One way is to use the ActiveWorkbook.Worksheets property. This will return a collection of all the worksheets in the workbook, including hidden worksheets. To just get the visible worksheets, you can use the Visible property like this:

For Each ws In ActiveWorkbook.Worksheets
    If ws.Visible = True Then
        'do something with the visible worksheet here
    End If
Next ws

Another way to select all visible worksheets is to use the Sheets property of the Application object. This will return a collection of all the worksheets in all open workbooks, including hidden worksheets. To just get the visible worksheets, you can use the Visible property like this:

For Each ws In Application.Sheets
    If ws.Visible = True Then
        'do something with the visible worksheet here
    End If
Next ws

Move beyond 

Excel

Get started with Causal today.
Build models effortlessly, connect them directly to your data, and share them with interactive dashboards and beautiful visuals.