VBA to hide rows

andy_2610

Board Regular
Joined
Jan 29, 2015
Messages
168
Hi all,

I need help with a vba code to hide rows based on certain criteria. I have a large range of data. Column A is the dependent to hiding the entire row.
For an example below:

ABCDE
1Invoiced10apples
2Paid10oranges
3Enroute20bananas
4Delivered15avocados
5Invoiced20watermelon
6Completed30Coffee

<tbody>
</tbody>

If Column A = "Invoiced", "Paid", or "Completed" then I want the entire row hidden. So in this case, row 1, 2, 5, and 6 should be hidden.

Thanks in advance,

Andrew
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

vcoolio

Well-known Member
Joined
Jun 29, 2014
Messages
1,395
Office Version
  1. 365
Platform
  1. Windows
Hello Andy,

Try this code in a standard module:-


Code:
Sub HideRows()

Dim lRow As Long
lRow = Range("A" & Rows.Count).End(xlUp).Row

For Each cell In Range("A1:A" & lRow)
     If cell = "Invoiced" Or cell = "Paid" Or cell = "Completed" Then
     cell.EntireRow.Hidden = True
     End If
Next

End Sub

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0

vcoolio

Well-known Member
Joined
Jun 29, 2014
Messages
1,395
Office Version
  1. 365
Platform
  1. Windows
Hi Andy,

Glad that I could help.

Cheerio,
vcoolio. :)
 
Upvote 0

Forum statistics

Threads
1,195,617
Messages
6,010,729
Members
441,565
Latest member
menangterus556

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top