### Description:

We are required to Hide-UnHide the rows in some types of requirements. For examples we may have data for 3 different categories of items and we may want to show the respective items based on selection. In this case we can achieve by Hiding or Un-hiding the Rows. We will see this in the following examples:

- Hide-UnHide Rows in Excel Worksheet using VBA – An Example
- Hide-UnHide Rows in Excel Worksheet using VBA – Case study
- Hide-UnHide Rows in Excel Worksheet using VBA – Download Example Files
- Hiding Rows with Criteria in Excel Worksheet using VBA – Example File

### Hide UnHide Rows in Excel Worksheet using VBA – Solution(s):

You can use EntireRow.Hidden property of Row. If you set hidden property TRUE, it will hide the rows. Or if you set it to FALSE then it will make rows to visible.

##### Hide-UnHide Rows in Excel Worksheet using VBA – An Example

The following example will show you how to Hide and Unhide the rows in excel worksheet using VBA. We can Hide or Unhide the multiple rows at a time. In this example I am hiding and Unhiding Rows 5 to 8.

###### Code:

Sub sbHidingUnHideRows() 'To Hide Rows 22 to 25 Rows("5:8").EntireRow.Hidden = True 'To UnHide Rows 22 to 25 Rows("5:8").EntireRow.Hidden = False End Sub

###### Instructions:

- Open an excel workbook
- Press Alt+F11 to open VBA Editor
- Insert a Module for Insert Menu
- Copy the above code and Paste in the code window
- Save the file as macro enabled workbook
- Press F5 to run it

###### Output:

Here is the example screen-shot. You can download the file below and see the code. Hide button will call the procedure to hide the rows and unhide button will unhide the rows. For example, Food Button will show you the data and charts related to food. And ‘Show All’ button will show you all categories and ‘Hide All’ button will hide all categories.

### Hide-UnHide Rows in Excel Worksheet using VBA – Case study

Here is the example case study. You can download the file below and see how its working. You can click on the buttons to view the respective data.

### Hide-UnHide Rows in Excel Worksheet using VBA – Download Example File

You can download the example file and see the code for each button.

ANALYSISTABS – Hide-Unhide Rows

## Hiding Rows based on a Condition

Let us assume we have 500 rows/records in a worksheet, we can loop through each row and check for a criteria and hide the rows. Let us see the verity of example with different criteria:

### Hide all rows with the text data /strings in Column A

The following example will hide all all rows with the text data /strings in Column A.

LastRow = 500 'Let's say you have 500 rows in the data For i = 1 To LastRow 'Now we loop through each row and check for required criteria 'To hide all the rows with the text data /strings in Column A If IsNumeric(Range("A" & i)) = False Then Rows(i).EntireRow.Hidden = True Next

### Hide all rows with the values as 0 in Column A

The following example will hide all all rows with the values as 0 in Column A.

LastRow = 500 'Let's say you have 500 rows in the data For i = 1 To LastRow 'Now we loop through each row and check for required criteria 'to hide all the rows with the values as 0 in Column A If Range("A" & i) = 0 Then Rows(i).EntireRow.Hidden = True Next

### Hide all rows with the negative values in Column A

The following example will hide all all rows with the negative values in Column A.

LastRow = 500 'Let's say you have 500 rows in the data For i = 1 To LastRow 'Now we loop through each row and check for required criteria 'to hide all the rows with the negative values in Column A If IsNumeric(Range("A" & i)) = True Then If Range("A" & i) < 0 Then Rows(i).EntireRow.Hidden = True End If Next

### Hide all rows with the Positive values in Column A

The following example will hide all all rows with the Positive values in Column A.

LastRow = 500 'Let's say you have 500 rows in the data For i = 1 To LastRow 'Now we loop through each row and check for required criteria 'to hide all the rows with the Positive values in Column A If IsNumeric(Range("A" & i)) = True Then If Range("A" & i) > 0 Then Rows(i).EntireRow.Hidden = True End If Next

### Hide all rows with the Even Number in Column A

The following example will hide all all rows with the Even Number in Column A.

LastRow = 500 'Let's say you have 500 rows in the data For i = 1 To LastRow 'Now we loop through each row and check for required criteria 'To hide all the rows with the Even Number in Column A If IsNumeric(Range("A" & i)) = True Then If Range("A" & i) Mod 2 = 0 Then Rows(i).EntireRow.Hidden = True End If Next

### Hide all rows with the Odd Number in Column A

The following example will hide all all rows with the Odd Number in Column A.

LastRow = 500 'Let's say you have 500 rows in the data For i = 1 To LastRow 'Now we loop through each row and check for required criteria 'To hide all the rows with the Odd Number in Column A If IsNumeric(Range("A" & i)) = True Then If Range("A" & i) Mod 2 = 1 Then Rows(i).EntireRow.Hidden = True End If Next

### Hide all rows if the value in Column A is greater than 50

The following example will hide all all rows if the value in Column A is greater than 50.

LastRow = 500 'Let's say you have 500 rows in the data For i = 1 To LastRow 'Now we loop through each row and check for required criteria 'To hide all the rows if the value in Column A is greater than 50 If IsNumeric(Range("A" & i)) = True Then If Range("A" & i) > 50 Then Rows(i).EntireRow.Hidden = True End If Next

### Hide all rows if the value in Column A is less than 100

The following example will hide all all rows if the value in Column A is less than 100.

LastRow = 500 'Let's say you have 500 rows in the data For i = 1 To LastRow 'Now we loop through each row and check for required criteria 'To hide all the rows if the value in Column A is less than 100 If IsNumeric(Range("A" & i)) = True Then If Range("A" & i) < 100 Then Rows(i).EntireRow.Hidden = True End If Next Next

Hey! Join Our Community

Get Quick Responses & Experts' Answers in Minutes!

Get Notified - When Answered Your Question!

LSJuly 24, 2015 at 10:23 AMIn case I want to hide a row with condition…… for eg. I have a data base with some columns having text and some having numbers. If value in one of the columns becomes 0 or a negative number or a text then that row should get hidden.

could you please automate such a task in excel ?

thanks.

PNRaoJuly 25, 2015 at 3:04 AMHi Lata,

I have updated the post with number of examples with criteria.

Please check now:Hiding Rows with Criteria in Excel Worksheet using VBA – Example File

Thanks-PNRao!

BenAugust 7, 2015 at 8:00 PMI tried to apply the same principle to columns with the conditions in row 1, but it can’t run.

Maybe someone knows what I need to fix in the script below :

Thanks!

LastColumn = “EZ” ‘Let’s say I have columns until “EZ” in the report

For i = “A” To LastColumn ‘I want to loop through each column and check for required criteria

‘to hide all the columns with the values as 0 in Row 1

If Range(1 & i) = 0 Then Column(i).EntireColumn.Hidden = True

Next

PNRaoAugust 8, 2015 at 3:25 PMHi Ben,

For loop takes numeric values, replacing your column names with column numbers will work for you, check the below examples

http://analysistabs.com/excel-vba/hide-unhide-columns-worksheet/#bm4

Thanks-PNRao!

BenAugust 11, 2015 at 7:21 PMAwesome!! Works like a charm,

Thanks again!

PNRaoAugust 11, 2015 at 11:51 PMWelcome! I’m glad it worked. Thanks-PNRao

patrickDecember 7, 2015 at 5:40 PMMy desire is to specific cells. I have checkboxes and command buttons sprinkled throughout the worksheet. What I like to do is to hide the cells containing these form types. Maybe I have to redesign my worksheet to have all these buttons and boxes either all in a row or a column and hide the row/column. Have not had much luck with this. Can you help please?

amina1987March 9, 2016 at 4:16 PMgood morning.

thank you for this very usefull topic.

for my work (for 2400 workbooks) i need to hide specific rows without openning the workbooks. is that possible? please help

Avishek BoseApril 16, 2016 at 4:02 PMHey Valli,

This is my first attempt to actually write a Macro, and looks like I am stuck (Terribly Stuck)

Here is what I am trying to achieve:

I have a “Input” sheet which is linked (Via Vlookups in C:C) to 8-10 other worksheets (containing rates of materials). On a daily basis I have to insert the quantities (in Column D:D) next to the rates in the “Input” Sheet to multiply it with the corresponding rates to arrive at the total amount (in Column E:E) eventually.

The issue is I have to hide the materials (Entire Rows) I do not use in the Input sheet as well as the other reference sheets. Is there any way a macro can be written to help me?

GuyMay 9, 2016 at 4:27 PMHI PNRao,

Thanks for the great poste it really helped me, how would i loop this macro round to unhide the hidden rows when the box is unchecked?

Thanks

SANDIP DAVEJanuary 3, 2017 at 8:01 PMI have a worksheet with live data of stock value, high, low in Column A3:A103, B3:B103, C3:C103 respectively and other formula in other columns and that updates every few seconds.

I would like to see only rows where below conditions is fulfilled and hide all other rows to filter out stocks.

Condition 1: =AND(A3=B3,A3>=L3,A3<=K3,A30)

Condition 2 =AND(A3=C3,A3>=S3,A3<=R3,A30)

Above condition is for example of Raw No.3 and which I am using for conditional formatting.

Kindly help to provide VBA codes for this.