DEV Community

Andrews
Andrews

Posted on • Originally published at geekexcel.com on

Hide Rows with Zero Value using Macros (VBA) in Excel Office 365!

In this guide, we will show you the simple steps to hide rows with zero value using Macros & VBA in Excel Office 365. Macros will make your work easy and simple, so you can finish any kind of task with a few clicks. Let’s get into this article, and know the clear-cut steps to achieve this task.

Hide Rows with Zero Value:

You need to follow the below steps to hide rows that contain zero values.

  • For instance, you can see the range of data regarding the student’s mark list in the below screenshot.
  • Here, we have shown the student id, name, and marks in the range A1:C5. We are going to hide the rows if the student mark is zero.

Input Range
Input Range

  • On the Developer Tab, select the Visual Basic option under the Code section.

Select Visual Basic option
Select the Visual Basic option

  • Then you need to copy and paste the code given below.

VBA code to hide rows using Macros

Sub HideRows()

Set myRange = Application.Selection

Set myRange = Application.InputBox(“Select one Range:”, “HideRows”)

for Each myCell In myRange

If myCell.Value = “0” Then

myCell.EntireRow.Hidden = True

End If

Next

End Sub

  • You need to save the code by selecting it. Then close the window.

Save the code
Save the code

  • You have to open the sheet containing the data. On the Developer Tab, choose the Macros option in the Code section.

Choose the Macros option
Choose the Macros option

  • You need to make sure that your macro is selected and click the Run button.

Click the Run button
Click the Run button

  • Then you need to select the range and click the OK button.

Click the OK button
Click the OK button

  • At last, you will see that the rows with zero value are hidden as shown in the below screenshot.

Result
Result

Closure:

In this guide, you can clearly learn the simple instructions to hide rows with zero value using Macros & VBA in Excel Office 365. Drop your suggestions/feedback in the below comment section. Thanks for visiting Geek Excel. Keep Learning!

Keep Reading:

Top comments (0)