Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a table of data with dates in the first column and then a bunch
of other data across the row. On top of this I have a beginning date cell and an ending date -- I would like to use VBA to hide the rows with dates outside of the period (bounded by the begin/end dates). How do I do this? Also if it could update as the begin/end dates change -- that would be ideal. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Private Sub Worksheet_Change(ByVal Target As Range) Dim i As Long On Error GoTo ws_exit: Application.EnableEvents = False If Not Intersect(Target, Me.Range("A1:B1")) Is Nothing Then Cells.Rows.Hidden = False For i = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1 If Cells(i, "A").Value < "" And _ (Cells(i, "A").Value < Range("A1").Value Or _ Cells(i, "A").Value Range("B1").Value) Then Rows(i).Hidden = True Else Rows(i).Hidden = False End If Next i End If ws_exit: Application.EnableEvents = True End Sub 'This is worksheet event code, which means that it needs to be 'placed in the appropriate worksheet code module, not a standard 'code module. To do this, right-click on the sheet tab, select 'the View Code option from the menu, and paste the code in. -- HTH Bob Phillips wrote in message ps.com... I have a table of data with dates in the first column and then a bunch of other data across the row. On top of this I have a beginning date cell and an ending date -- I would like to use VBA to hide the rows with dates outside of the period (bounded by the begin/end dates). How do I do this? Also if it could update as the begin/end dates change -- that would be ideal. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks -- I'm having a hard time with this -- I haven't used Visual
Basic really since I was in high school -- Could you explain what the code is doing (i.e. how I can adapt it to my spreadsheet)? |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Private Sub Worksheet_Change(ByVal Target As Range) Dim i As Long On Error GoTo ws_exit: Handle errors, and reset events in this case Application.EnableEvents = False This is just to stop this code creating a cascade of changes If Not Intersect(Target, Me.Range("A1:B1")) Is Nothing Then This checks whether cells A1 and B1 have changed or not, which is where I assumed you would store your two dates. Change to suit. Cells.Rows.Hidden = False Unhides all rows in case there is one hidden that would not now be hidden due to a changed date For i = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1 Find the bottom row and step back one row at a time If Cells(i, "A").Value < "" And _ (Cells(i, "A").Value < Range("A1").Value Or _ Cells(i, "A").Value Range("B1").Value) Then If the date in the current row in column A (change to suit) is less than the earlier stored date or greater than the later stored date, then ... Rows(i).Hidden = True Hide the row Else Rows(i).Hidden = False This is actually redundant. End If Next i End If ws_exit: Application.EnableEvents = True Set events back on again. End Sub Note where the code is stored as per my original reoply. -- HTH Bob Phillips wrote in message ups.com... Thanks -- I'm having a hard time with this -- I haven't used Visual Basic really since I was in high school -- Could you explain what the code is doing (i.e. how I can adapt it to my spreadsheet)? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Color alternate rows when after hiding selected rows | Excel Worksheet Functions | |||
Hiding Specific Rows Based on Values in Other Rows | Excel Worksheet Functions | |||
Hiding a button when hiding rows | Excel Discussion (Misc queries) | |||
Hiding Rows if the linked rows are blank | Excel Discussion (Misc queries) | |||
Copying Rows when hiding other rows | Excel Worksheet Functions |