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

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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
 

jessieo387

New Member
Joined
Jun 10, 2009
Messages
40
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
 

Watch MrExcel Video

Forum statistics

Threads
1,132,872
Messages
5,655,725
Members
418,234
Latest member
jdorfma

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