Using a Variable Range to Hide Rows

Aprez76

New Member
Joined
Aug 7, 2008
Messages
23
Looking for some help hidding rows. I have a data set that is variable in size but no larger than 3000 rows. I would like to write some VB code that based on a value in column A (which is already sorted by Yes then NO) finds the first row with a value of "No" and hides that row and all rows that follow, all the way to Row 3000. Ultimatly hidding all rows in the data set that have the value NO in Column A. Since the data is sorted I'm sure I do not have to loop through each value in column A but rather find the first "No" value and hide everything that follows.

Any help is appreciated.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Welcome to the Board.

What you ask can be done with VBA, however, if this is the only data on the sheet you could use Auto Filter to display everything but No's by selecting Custom option on appropriate Column and setting conditional rule -> does not equal No.
 
Upvote 0
I'm looking to do this using VBA versus the auto filter approach as it ties into a larger project that includes some VBA.
 
Upvote 0
Code:
Sub Standard()
'---------------------------------------
Dim row_1 As Long: row_1 = 1
Dim row_2 As Long: row_2 = 3000
Dim col As Integer: col = 1     'Col A
'---------------------------------------
On Error GoTo NoNo
row_1 = Application.WorksheetFunction.Match("No", Range(Cells(row_1, col), Cells(row_2, col)), 0) + (row_1 - 1)
Rows(row_1 & ":" & row_2).Hidden = True
Exit Sub
'nothing to hide ?
NoNo:
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,474
Messages
6,130,841
Members
449,598
Latest member
sunny_ksy

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
Back
Top