Hide Rows in Excel (Using Shortcuts, Commands and VBA)

In this context, we will explain approaches to hide rows in Excel. While constructing approaches, we will use the Format command, keyboard shortcut, and Group command. Additionally, we intend to discuss the use of the Toggle button and VBA Macro incorporating VBA code.

Often we need to hide unwanted rows to make the necessary rows worthy. Also, the dataset may contain inappropriate information as well as blank cells. Thus hiding rows is not a choice, rather it is compulsory for professionals.

hide rows in excel


Download Practice Workbook


How to Hide Rows in Excel


1. Use Format Menu to Hide Rows

You can use the Format menu to hide within a single moment.

  • Initially, click on the row number of a row >> Then drag down the cursor or hold the SHIFT key to select contiguous multiple rows.
  • To hide rows 10-12, Select the rows 10,11,12 >> Then go to the Home tab >> Next expand the Cells command >> Further expand the Format command >> click on the Hide & Unhide option >> Finally select the Hide Rows option.

Selecting hide rows option

  • Subsequently, you will be able to hide the 10th, 11th, and 12th rows.

hidden rows in Excel

Read More: How to Unhide Rows in Excel


2. Hide Rows Using the Context Menu

In this method, we will explore the steps to unhide rows by using the Context menu.

  • In the beginning, select rows 10 to 12 >> Right-Click on the Mouse to get the Context menu >> Click on the hide option from the Context menu list.

using hide option from the context menu

  • Immediately, we don’t observe the existence of rows 10th, 11th, and 12th.

hidden rows in Excel

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


3. Apply Excel Keyboard Shortcut to Hide Rows

More importantly, you may utilize the keyboard shortcut for hiding rows.

  • To use the keyboard shortcut you have to select the rows first >> Press CTRL + 9 keys altogether.

using keyboard shortcut

  • Therefore, we get the output hiding rows.

hidden rows in Excel

Note: Shortcut for Windows: CTRL + 9 and for Mac: ^ + 9.

Read More: Hide Rows and Columns in Excel: Shortcut & Other Techniques


4. Hide Rows via Excel Group Command

Sometimes we must work with a group of rows and hide grouped rows. Fortunately, you can do this by using the Group command and clicking on the minus sign only.

  • Primarily, select rows (10-12) >> Then go to the Data tab >> Next expand the Outline command >> Finally, click on the Group command.

Using Group command

  • Meanwhile, a Minus (-) sign will be available at the end of the 12th row >> Next, click on the Minus sign.

Clicking on the minus icon

  • Shortly, you’ll get the following output where the selected rows 10-12 are hidden.

Rows hidden


5. Create Toggle Button to Hide Rows

At this time, you’re going to witness an amazing tool by creating a button to hide rows. Thus by clicking on the button, it will automatically hide your selected rows.

  • Initially, go to Developer tab >> Then Insert button >> Next pick the Toggle Button from the ActiveX Controls section.
  • Further, locate the Toggle button and re-configure with the VBA code by double-clicking the button.

Using toggle button

  • Enter the following VBA code in the worksheet and hit on the Run icon.
Private Sub ToggleButton1_Click()
Dim xRow As String
xRow = "10:12"
If ToggleButton1.Value Then
    Application.ActiveSheet.Rows(xRow).Hidden = True
    ToggleButton1.Caption = "Unhide Row"
Else
    Application.ActiveSheet.Rows(xRow).Hidden = False
    ToggleButton1.Caption = "Hiding the Selected Rows"
End If
End Sub

Excel VBA code to hide rows via toggle button

Code Breakdown

  • In the above code, I declare xRow as a String type.
  • Then I set the value of xRow as “10:12” as I want to hide rows 10-12.
  • Eventually, I use the ToogleButton.Value property to specify the object.
  • Later, Application.ActiveSheet property is used to extract the value of the running sheet.
  • Right then, Rows(xRow).Hidden is set to True to hide the selected rows, and the same condition (except the Hidden is set to False) was applied to the rest to unhide the rows.
  • Finally, rows 10-12 are no more visible once we click on the Hide Rows button.

hidden rows via Excel toggle button

  • Happily, you’ll get the hidden rows again by clicking on the Unhide Rows button.

Read More: [Fix]: Unable to Unhide Rows in Excel


6. Hide Rows Applying Excel VBA

Last but not least, if you want to apply the VBA code to hide rows, you can do that effectively as the code is quite simple. To apply the VBA code, you need to insert a module.

  • Firstly, open a module by clicking Developer > Visual Basic.

How to Insert VBA Code

⇰ Secondly, go to Insert > Module.

How to Insert VBA Code

Now, we will show you three applications with VBA Macro.


6.1. Hide a Single Row

Perhaps, you need to hide a single row e.g. row 10 as shown in the following picture. insert the following code in the VBA module and press the F5 button or hit the Run icon.

Sub Hide_Singe_Row_VBA()
Rows("10").Hidden = True
End Sub

Using Excel VBA to hide single row.

Read More: How to Unhide Top Rows in Excel


6.2. Hiding Multiple Adjacent Rows Applying VBA Code

In case we require to hide multiple contiguous rows e.g. rows 10-12. By inserting the following VBA code into the created module and clicking on the Run icon or pressing the F5 button, we obtain the obtain as you can see in the image.

Sub Hide_Adjacent_Rows_VBA()
Rows("10:12").Hidden = True
End Sub

Excel VBA to hide multiple adjacent rows.

Read More: Hide Rows Based on Cell Value Conditional Formatting


6.3. Hiding Multiple Non-Adjacent Rows Applying VBA Code

If you want to hide multiple rows but they are not contiguous e.g. rows 5-6 & rows 9-11, you can use this method by inserting the following code in the VBA module and press the F5 button or hit the Run icon.

Sub Hide_NonAdjacent_Rows_VBA()
Rows("5:6").Hidden = True
Rows("9:12").Hidden = True
End Sub

Excel VBA to hide multiple non-adjacent rows.


How to Hide Rows Containing Blank Cells in Excel

1.  Apply Filter Feature

Users can quickly filter out and hide the blank cells using the Filter tool.

  • To filter the B4:E14 range, select the B4:E4 range >> Go to the Data menu >> Expand the Sort & Filter command >> click on the Filter command.

Using Filter tool

  • Next, expand the drop-down box >> De-select the Blanks option from the list.

De-selecting blanks

  • Therefore, rows 8th and 12th containing blanks are hidden.

rows hidden containing blank cell in Excel


2. Use Find and Replace Tool

You can figure out the positions of blank cells using the Find and Replace tool.

  • Select the B4:E14 range >> Press Ctrl + F to open the Find and Replace dialog.
  • From the Find and Replace dialog, go to the Find tab >> Leave blank the Find what field >> Click on the Find All button.
  • Thus 2 cells having blanks appears.

Using the Find and Replace feature.

  • Further, select the blanks D8 and D12 >> Go to the Home tab >> Expand the Cells command >> Expand the Format command >> Click on the Hide & Unhide option >> Select the Hide Rows option.

Selecting hide rows option.

  • Therefore, we obtain the result hiding the rows containing blank cells.

rows of blank cells are hidden


3. Apply Go To Special Tool

With the help of the Go to Special tool, you can navigate the blank cells. Thus it will be easier for us to hide those rows.

  • To begin the process, select the B4:E14 range >> Press the Ctrl + G to open the Go To dialog >> Click on the Special button.

Getting the Go To Special tool.

  • Thus Go To Special dialog appears. Choose Blanks >> Select the OK button.

Selecting blanks

  • Next, select the blanks D8 and D12 >> Go to the Home tab >> Expand the Cells command >> Expand the Format command >> Click on the Hide & Unhide option >> Select the Hide Rows option.

Selecting hide rows option

  • In the end, we obtain the outcome by hiding the blank cells.

Rows hidden containing blanks


How to Unhide Rows in Excel


1. Use Format Command

Like hiding rows, you can also unhide rows by using the Format command of the Home tab.

  • Initially, Select the B4:D14 range >> Go to the Home tab >> Expand the Cells command >> Expand the Format command >> Click on the Hide & Unhide option >> Select the Unhide Rows option.

Using unhide option

  • Thus we obtain unhidden rows.

unhidden rows in Excel


2. Use Context Menu

Users can unhide rows by using the Context menu.

  • In the beginning, select rows 9 to 13 >> Right-Click on the Mouse to get the Context menu >> Click on Unhide option from the Context menu list.

using hide option from the context menu

  • As you can see in the image we obtain unhidden rows.

Rows are unhidden.


3. Apply Keyboard Shortcut

Application of the keyboard shortcut can accelerate you to unhide the hidden rows.

  • Initially, select rows 9 to 13 >> Press the Ctrl + Shift + 9 keys to unhide the rows.

using keyboard shortcut

  • Therefore, we achieve the unhidden rows as you can observe in the image.

unhidden rows in excel


Frequently Asked Questions (FAQs)

Q1. How do I hide specific rows in Excel?

Using the Find and Replace dialog you can find the specific data from the data range and hide the rows. From the Find and Replace dialog, go to the Find tab >> Insert text/numbers in the Find what field >> Click on the Find All button. Thus specific cells will be shown >> Then, press Ctrl + 9 to hide rows.

Q2. What is the shortcut to hide rows or columns in Excel?

Press Shift + 9 to hide rows whereas Shift + 0 for columns.

Q3. How to hide rows based on condition in Excel?

Users can hide rows based on conditions automatically by using the Excel VBA code with a suitable condition. However, using Filter or Find tool, one can figure out cells based on condition and hide rows manually.

Q4. Can Conditional Formatting hide rows in Excel?

No, the Conditional Formatting can’t hide or change height rows. Rather it allows specific conditions to highlight cells. To hide rows based on condition, you require to use a VBA code.


Hide Rows in Excel: Knowledge Hub


Conclusion

In short, you may hide rows in Excel utilizing the above methods. Further, if you are keen enough to learn some advanced approaches to hide unhide rows, you can follow the resources from the Knowledge Hub section. Please use the comment section below to leave your thoughts. However, any suggestions regarding the article are appreciated.


<< Go Back to Rows in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
MD Tanvir Rahman
MD Tanvir Rahman

MD Tanvir Rahman, BUET graduate in Naval Architecture and Marine Engineering, dedicated over a year to the ExcelDemy project. He is an Excel and VBA Content Developer. Having authored 50+ insightful articles, he actively updates and improves over 80 articles, reflecting his commitment to accuracy and currency, managing day-to-day operations, and analyzing and developing Excel and VBA tutorials. His broad interests encompass Data Analysis, Advanced Excel, VBA Macro, Excel Templates, Excel Automation, and Excel Power Query, showcasing a... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo