Excel VBA to Delete Rows Based on Date & Time

browncountry

New Member
Joined
Feb 2, 2019
Messages
13
F
G
1
DATE
TIME
2
2/19/2019
18:00
3
2/19/2019
23:20
4
2/19/2019
3:30
5
2/20/2019
6:30
6
2/20/2019
7:00
7
2/20/2019
8:00

<tbody>
</tbody>

I'm having trouble deleting rows based on date & time. I have a report that exports transaction dates and times in Columns F & G respectively. Time exports as a text field. The idea is to delete rows from the earlier (MIN) date that are less than Time Value 20:00 and all rows from the latter date (MAX) greater than Tim Value 6:30.

I am able to create formulas to mark these rows, but I just don't know how to translate that to VBA code.

These are formulas I created to mark rows to KEEP.
=IF(AND(F2=MIN(F:F),TIMEVALUE(G2)>TIMEVALUE("20:00")),"x","")
=IF(AND(F2=MAX(F:F),TIMEVALUE(G2)<timevalue("6:30")),"x","")


In my example, Rows 3-5 would not be deleted. This comes from and 3rd shift production report so dates vary. That's why I figured MIN and MAX functions could be incorporated. Please help. Thanks!</timevalue("6:30")),"x","")
 

Some videos you may like

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Col Delane

Active Member
Joined
Jan 14, 2014
Messages
303
Have you considered:

  1. Creating an Excel Table in a template worksheet that contains:
    1. your formula to flag rows for deletion (that should auto replicate in the Table to cover any additional data rows)
    2. columns for your new data
  2. Paste your new data into the template
  3. Apply filter to "Delete These" column where value = "X"
  4. Select all visible rows in the table (should only be those to delete)
  5. Select "Visible cells only" (F5 [Goto], Special, Visible cells only) >> you can also add a built-in button for this command to your QAT
  6. Delete rows
  7. Clear filter

If you don't have to do this task very often, the above doesn't take much time to do manually, avoiding the need for VBA.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,360
Messages
5,528,243
Members
409,809
Latest member
VICKRAM

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top