[pre]
[/pre]
Toggles the AutoFilter on/off. Hence why you would want to remove this line if you are already using AutoFilters
'Filter down to just the relevant info
ActiveSheet.Range("A1".AutoFilter Field:=4, Criteria1:= _
"<=" & TimeStamp[/code][/pre]
Now that AutoFilter is on, applies a filter to the fourth filter (aka, column D). Criteria being everything that is less than or equal to TimeStamp, which we defined earlier as the date/time value from column D.
Set xSelect = DTable.Offset(1, 0).Resize(DTable.Rows.Count - 1, _
DTable.Columns.Count).SpecialCells(xlCellTypeVisible).EntireRow[/code][/pre]
This is the somewhat tricky one. I need to define the range of visible cells that are shown after applying the filter. Starting with DTable, we shift 1 row down so we don't include the header row. Then, we resize the area to be 1 row less than DTable was but the same number of columns. So, if DTable was A1:D5, we're no looking at A2:D5. Then, I used SpecialCells to only look at the visible cells within that range, and finally, I tell it to take the Entire Row of those cells (that were visible).
Code:
TimeStamp = Cells(ActiveCell.Row, "D").Value
Stove the Time stamp from column D in the same row as the cell that is currently selected. So, if you select cell C3 and then run the macro, it will store the value from D3 into TimeStamp.
[pre][code]Set DTable = Selection.CurrentRegion
Current Region is the "block" of cells that the object (in this case, the current selection) is in. Knowing that your data is in a table, this defines DTable as the entire data table. We want to know this so we can apply the AutoFilter to the whole table.
[pre][code]'Delete this line if AutoFilter is already active
DTable.AutoFilter
Toggles the AutoFilter on/off. Hence why you would want to remove this line if you are already using AutoFilters
'Filter down to just the relevant info
ActiveSheet.Range("A1".AutoFilter Field:=4, Criteria1:= _
"<=" & TimeStamp[/code][/pre]
Now that AutoFilter is on, applies a filter to the fourth filter (aka, column D). Criteria being everything that is less than or equal to TimeStamp, which we defined earlier as the date/time value from column D.
Set xSelect = DTable.Offset(1, 0).Resize(DTable.Rows.Count - 1, _
DTable.Columns.Count).SpecialCells(xlCellTypeVisible).EntireRow[/code][/pre]
This is the somewhat tricky one. I need to define the range of visible cells that are shown after applying the filter. Starting with DTable, we shift 1 row down so we don't include the header row. Then, we resize the area to be 1 row less than DTable was but the same number of columns. So, if DTable was A1:D5, we're no looking at A2:D5. Then, I used SpecialCells to only look at the visible cells within that range, and finally, I tell it to take the Entire Row of those cells (that were visible).