Hide Rows VBA Code Not Working

jessieo387

New Member
Joined
Jun 10, 2009
Messages
40
Hello,

I am trying to write so simple code to hide rows based on dates entered.

Here is the code:

Sub HideRows()
For Each cell In ActiveSheet.Range("A6:A380")
If cell.Value < "B1" Or cell.Value > "B2" Then cell.EntireRow.Hidden = True
Next
End Sub


Cells A6:A380 are dates and cell B1 is the start date and cell B2 is the end date. The data on this Worksheets is for the entire year, and I want to be able to select just certain data to view and have the other data hidden.

Thanks,

Jessica
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Try

Code:
Sub HideRows()
For Each cell In ActiveSheet.Range("A6:A380")
If cell.Value < Range("B1").Value Or cell.Value > Range("B2").Value Then cell.EntireRow.Hidden = True
Next
End Sub
 
Upvote 0
That worked! Thanks so much! I figured it had something to do with specifying a value for the call but wasn't sure what!

Jessica
 
Upvote 0

Forum statistics

Threads
1,214,895
Messages
6,122,128
Members
449,066
Latest member
Andyg666

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