How To Hide Every Other Row in Excel (Using VBA)

This post will show you how to hide alternate rows or columns in Excel or how to hide every third, fourth, fifth row or column in Excel. If you want to hide every other row in your current worksheet, how to do it quickly in Excel 2013 or excel 2016. How do I hide the row one after another using VBA Macro in Excel.

Assuming that you have a data set where you want to hide the alternate rows, so you want to hide row number 3,5,and 7. You can do it by manually, but if you are working with large data sets in your worksheet, and doing it manually is not an good option. So you can use other methods using VBA Macro I show you in the below steps.

hide every other row1

Hiding Every Other Rows with VBA Macro

If you want to quickly hide every other row in your selected range in Excel, and you can use the following short VBA code to achieve the result. Just do the following steps:

Step 1: On current visible worksheet, right click on sheet name tab to load Sheet management menu. Select View CodeMicrosoft Visual Basic for Applications window pops up.

hide every other row1

Or you can enter Microsoft Visual Basic for Applications window via Developer->Visual Basic. You can also press Alt + F11 keys simultaneously to open it.

How to Remove All Extra Spaces and Keep Only One Between Words 5

Step 2: In Microsoft Visual Basic for Applications window, enter below code:

Sub HideOtherRow()
    Dim myRange As Range
    Dim myRows As Long
    On Error Resume Next
    myTitle = "Hide Every Other Row"
    Set myRange = Application.Selection
    Set myRange = Application.InputBox("select a range", myTitle, myRange.Address, Type:=8)
    myRows = myRange.Rows.Count
    For i = 1 To myRows Step 2
        myRange.Rows(i).Hidden = True
    Next i
End Sub

hide every other row1

Step 3: Save code, quit Microsoft Visual Basic for Applications.

Step 4: Click Developer->Macros to run Macro.

Highlight All Non-Blank Cells 13

Step 5: Select the Macro Name ‘HideOtherRow’  from the Macro window and click Run.

hide every other row1

Step 6: you need to selete one range that you wish to hide rows, such as: $A$1:$B$13, then clicking Ok button.

hide every other row1

Step 6: Once you have clicked “Ok” button in the step 5, it will go through each row and hide every other row in your selected range. see the below result:

 hide every other row1

Note: when you have a VBA Macor in your workbook, and you need to save it as a Macro-enabled file with the .XLSM extension in Excel. Since there are any changes made by the VBA Macor are ireversible, and you’d better to make a backup copy of your workbook or worksheet firstly and then run the VBA code.

In case you want to hide every third rows, and you can use the VBA Macor below:

Sub HideOtherRow()
  Dim myRange As Range
  Dim myRows As Long
  On Error Resume Next
  myTitle = "Hide Every Other Row"
  Set myRange = Application.Selection
  Set myRange = Application.InputBox("select a range", myTitle, myRange.Address, Type:=8)
  myRows = myRange.Rows.Count
  For i = 1 To myRows Step 3
    myRange.Rows(i).Hidden = True
  Next i
End Sub

You just need to adjust according to hide the Nth row in the above code.

hide every other row13

Related Posts
VBA Macro For VLOOKUP From Another Sheet
vba macro for vlookup from another sheet1

In the previous post, you should know that how to fix or remove the #N/A error when using VLOOKUP formula to lookup value from another sheet. And this post will show you how to use VBA code to vlookup data ...

How To Insert Comments in Protected Worksheet in Excel
insert commetns in protected workshee3

This post will show you how to allow comments in a protected worksheet in Excel. You can easily to insert comments into cells in a normal worksheet in Excel, but if want to insert a comment in a worksheet that ...

How To Convert Text to Upper Cases(Using VBA) in Excel
convert text to upper cases1

This post will show you how to switch from lower case to upper case in Excel. and I am going to show you two different ways of converting text to upper cases using formula or VBA macro in Excel 2013,Excel ...

How to Disable the Save As Prompt in Excel
disable save as prompt1

This post will show you how to use a VBA Macro to save an Excel file and overwrite any existing file without a prompt so that you are going to get the little window that says file already exists do ...

How to Count Cells that Contain even or odd numbers in Excel
count cells that contain even numbers5

This post will guide you how to count the number of cells that contain odd or even numbers within a range of cells using a formula in Excel 2013/2016.How do I count cells that contain odd numbers through the use ...

How to Count Cells that Contain negative Numbers in Excel

This post will guide you how to count the number of cells that contain negative numbers within a range of cells using a formula in Excel 2013/2016.You can count the number of negative numbers in your data using easy functions ...

How to Count Cells Are Not Blank or Empty in Excel
count non blank nonempty cells5

This post will guide you how to count cells that are not blank or empty in a given range cells using a formula in Excel 2013/2016.How do I count the number of cells that are not blank in a particular ...

How to Count Cells Less Than a Specific Value in Excel
count cells lessr than5

This post will guide you how to count the number of cells less than a particular numeric value in a given range cells using a formula in Excel 2013/2016. How do I count cells that are less than a specific ...

How to Count Cells Greater Than a Specific Value in Excel
count cells greater than 5

This post will guide you how to count the number of cells greater than a particular numeric value in a given range cells using a formula in Excel 2013/2016. How do I count cells that are greater than a specific ...

How to Remove All Extra Spaces and Keep Only One Between Words in Excel
How to Remove All Extra Spaces and Keep Only One Between Words 7

Sometimes when copying something from other type files to excel, there might be two or more spaces display between words. Extra spaces between words are frequently to be seen in excel, and this behavior is very annoying. If we want ...

Sidebar