### 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:

**PREMIUM TEMPLATES LIMITED TIME OFFER**

**ON SALE80% OFF**

50+ Project Management Templates Pack

Excel PowerPoint Word

Advanced Project Plan & Portfolio Template

Excel Template

Business Presentations Templates Pack

PowerPoint Slides

20+ Excel Project Management Pack

Excel Templates

20+ PowerPoint Project Management Pack

PowerPoint Templates

10+ MS Word Project Management Pack

Word Templates

- 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

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.

SkupJune 26, 2017 at 11:52 AMGreetings,

How would someone show/hide rows in a 2nd range based upon the visibility of rows in a filtered range?

For example, if rows 5 through 20 are autofiltered by some criteria such that at a given state only rows 6, 8. 12. and 16 through 18 are visible, how could someone then show the matching rows in the range of rows from 105 through 120, so that along with rows 6, 8. 12. and 16 through 18 being visible by filtering; rows 106, 108, 112, 116, 117, and 118 are visible, while rows 105, 107, 109, 110, 11, 113, 114, 115, 119, and 120 are hidden?

How can this be triggered by the setting and resetting of the autofilter on the filtered range?