Automate rows to disappear?

Noxqss38242

Board Regular
Joined
Sep 15, 2017
Messages
225
Office Version
  1. 2016
I'm tracking trucks and their "down-time."

Is it possible to "extract" row data automatically based on an end-date in a column?
OR
Is it possible to have the row automatically "hide" when an end-date is entered into said column?

Ideally, if an end date is entered, the row would transfer to another workbook automatically (or another tab within the workbook if that is easier).
If the data is erased from the column, the "transferred data" would remain though (if possible).
If all else fails, maybe even just automatically "hide" the row if an "end-date" is entered in a particular column.

(Doesn't have to be a date, just any data placed into that column if that is also easier to write code for).
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I'm tracking trucks and their "down-time."

Is it possible to "extract" row data automatically based on an end-date in a column?
OR
Is it possible to have the row automatically "hide" when an end-date is entered into said column?

Ideally, if an end date is entered, the row would transfer to another workbook automatically (or another tab within the workbook if that is easier).
If the data is erased from the column, the "transferred data" would remain though (if possible).
If all else fails, maybe even just automatically "hide" the row if an "end-date" is entered in a particular column.

(Doesn't have to be a date, just any data placed into that column if that is also easier to write code for).

You'll need some modest code for the worksheet's Worksheet_Change. It goes into the "code module" for the worksheet. Below is an example that I tested.

VBA Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

'   In this EXAMPLE end-dates are in column 5 (E). Change as needed.
    If Target.Column = 5 _
     Then

        If IsDate(Target.Value) Then Target.EntireRow.Hidden = True

    End If

End Sub

This will hide any row if a date is entered into ANY cell in column 5 (E).

Jim
 
Upvote 0
I would suggest a slight change so that if multiple cells are entered at once (eg with Ctrl+Enter or by pasting) the appropriate row(s) would still be hidden.
I have also used column E as the example column

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Changed As Range, c As Range

  Set Changed = Intersect(Target, Columns("E"))
  If Not Changed Is Nothing Then
    For Each c In Changed
      If IsDate(c.Value) Then c.EntireRow.Hidden = True
    Next c
  End If
End Sub

(Doesn't have to be a date, just any data placed into that column if that is also easier to write code for).
It isn't any easier but if you wanted this you could try the following slight modification. In this one I have also excluded row 1 as I assume headings in that row and you wouldn't want to hide it if a new heading was put in the relevant column

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Changed As Range, c As Range
  
  Set Changed = Intersect(Target, Range("E2:E" & Rows.Count))
  If Not Changed Is Nothing Then
    For Each c In Changed
      If Len(c.Value) > 0 Then c.EntireRow.Hidden = True
    Next c
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,155
Members
453,021
Latest member
Justyna P

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