How to Hide the Same Rows Across Multiple Excel Worksheets

The sample dataset has three sheets and contains sales data of different regions.

Hide the Same Rows Across Multiple Excel Worksheets


Macro 1 – Hiding All the Same Rows Across Multiple Excel Worksheets

The first macro will hide all the same specific rows from all the sheets from our workbook. We’ll hide rows from 10 to 12 in every sheet.

Steps:

  • Press ALT + F11 to open the VBA window.
  • Click Insert > Module to insert a new module.

Hiding All the Same Rows Across Multiple Excel Worksheets

  • Enter the following codes in the module.
Sub HideRows_from_AllSheets()
    Dim WoSheet As Worksheet
    Dim miRng As Range, mitRng As Range
    For Each WoSheet In ThisWorkbook.Worksheets
        With WoSheet
            Set miRng = .Range("A10:A12")
            For Each mitRng In miRng.Cells
                mitRng.EntireRow.Hidden = Len(mitRng.Text) = 0
            Next mitRng
        End With
    Next WoSheet
End Sub
  • Go back to your sheet.

Codes to Hide All the Same Rows Across Multiple Excel Worksheets

Code Breakdown:

  • We created a Sub procedure- HideRows_from_AllSheets.
  • We declared some variables, WoSheet as Worksheet and miRng, mitRng as Range.
  • We have used the For Each statement to select all the worksheets and set the range of rows.
  • If you want to hide rows from specifically selected sheets, use this line instead of the 4th line of the above code- For Each ws In ThisWorkbook.Worksheets(Array(“Sheet1”, “Sheet3”, “Sheet5”)).

  • Click on Macros from the Developer ribbon.

Open Macro to Hide the Same Rows Across Multiple Excel Worksheets

  • After Macro dialog box opens up, choose the specified macro name and press Run.

The mentioned rows are hidden on every page. Here’s the output of sheet1.

The output of sheet2.

Read More: VBA to Hide Rows in Excel


Macro 2 – Hiding Rows from Multiple Worksheets Based on a Cell Value

We’ll hide some rows from multiple sheets based on a cell value, which means that if we get a specific value in a particular sheet, the macro will hide the selected rows from all the sheets of the workbook.

We’ll check Cell B4, if the cell contains ‘Salesperson’, the macro will hide rows 10 to 12 from every sheet of the workbook.

Hiding Rows from Multiple Worksheets Based on a Cell Value

Steps:

Sub HideRows_BasedOn_CellValue()
Dim WoSheet As Worksheet
Application.ScreenUpdating = False
For Each WoSheet In Worksheets
    beginRow = 10
    endRow = 12
    For Rowcnt = beginRow To endRow
        If Sheets("Based on a Cell Value").Range("B4").Value = "Salesperson" Then
            WoSheet.Rows(Rowcnt).EntireRow.Hidden = True
        Else
            WoSheet.Rows(Rowcnt).EntireRow.Hidden = False
        End If
    Next Rowcnt
Next WoSheet
Application.ScreenUpdating = True
End Sub
  • Go back to your worksheet.

Insert Codes to Hide Rows from Multiple Worksheets Based on a Cell Value

Code Breakdown:

  • In the above code, we created a Sub procedure first- HideRows_BasedOn_CellValue.
  • Then declared a variable, WoSheet as Worksheet.
  • And applied the For Each statement to select the row range.
  • We have used the For loop and If statement to look up the base value in the specified worksheet.

Select the Macro Name to Hide Rows from Multiple Worksheets Based on a Cell Value

As Cell B4 contains the value- ‘Salesperson’, so the rows from 10 to 12 have been hidden from the all worksheets. This is the output of the main sheet.

The following is the output of sheet1. You will get the same output in all the worksheets.

Read More: How to Hide Rows Based on Cell Value in Excel


Download Practice Workbook


Related Articles


<< Go Back to Hide Rows | Rows in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Kawser Ahmed
Kawser Ahmed

Kawser Ahmed is a Microsoft Excel Expert, Udemy Course Instructor, Data Analyst, Finance professional, and Chief Editor of ExcelDemy. He is the founder and CEO of SOFTEKO (a software and content marketing company). He has a B.Sc in Electrical and Electronics Engineering. As a Udemy instructor, he offers 8 acclaimed Excel courses, one selected for Udemy Business. A devoted MS Excel enthusiast, Kawser has contributed over 200 articles and reviewed thousands more. His expertise extends to Data Analysis,... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo