ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete all rows not today (https://www.excelbanter.com/excel-programming/363933-delete-all-rows-not-today.html)

SITCFanTN

Delete all rows not today
 
Can somebody please help me with this code, I'm trying to delete all rows
that are not dated the current date. My date format in column F is
mm/dd/yyyy, do I need to state that. Thanks

LastRow = Cells(Rows.Count, "F").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If StrComp(Cells(RowNdx, "F"), =Today(), vbTextCompare) < 0 Then
Rows(RowNdx).Delete
End If
Next RowNdx

somethinglikeant

Delete all rows not today
 
Sub DeleteNotCurrentDate()
qend = [F65536].End(xlUp).Row
Range("F" & qend).Select:
For i = qend To 1 Step -1:
Range("F" & i).Select
If ActiveCell.Value < Date Then ActiveCell.EntireRow.Delete
Next i
End Sub

somethinglikeant


SITCFanTN wrote:
Can somebody please help me with this code, I'm trying to delete all rows
that are not dated the current date. My date format in column F is
mm/dd/yyyy, do I need to state that. Thanks

LastRow = Cells(Rows.Count, "F").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If StrComp(Cells(RowNdx, "F"), =Today(), vbTextCompare) < 0 Then
Rows(RowNdx).Delete
End If
Next RowNdx



Paul Mathews

Delete all rows not today
 
Sub DelTodayRows()
'Deletes rows where the value in column F is today's date
Dim RowNdx As Long
Dim LastRow As Long

LastRow = Cells(Rows.Count, "F").End(xlUp).Row

For RowNdx = LastRow To 1 Step -1

If Cells(RowNdx, "F").Value = FormatDateTime(Now, vbShortDate) =
True Then
Rows(RowNdx).Delete
End If

Next RowNdx

End Sub

"SITCFanTN" wrote:

Can somebody please help me with this code, I'm trying to delete all rows
that are not dated the current date. My date format in column F is
mm/dd/yyyy, do I need to state that. Thanks

LastRow = Cells(Rows.Count, "F").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If StrComp(Cells(RowNdx, "F"), =Today(), vbTextCompare) < 0 Then
Rows(RowNdx).Delete
End If
Next RowNdx


SITCFanTN

Delete all rows not today
 
Oops Paul, maybe I'm doing this the wrong way...I only want to keep rows with
the current date....this code deletes the current date rows. Should I relook
at this and delete all rows not the current date? What is the best option?

"Paul Mathews" wrote:

Sub DelTodayRows()
'Deletes rows where the value in column F is today's date
Dim RowNdx As Long
Dim LastRow As Long

LastRow = Cells(Rows.Count, "F").End(xlUp).Row

For RowNdx = LastRow To 1 Step -1

If Cells(RowNdx, "F").Value = FormatDateTime(Now, vbShortDate) =
True Then
Rows(RowNdx).Delete
End If

Next RowNdx

End Sub

"SITCFanTN" wrote:

Can somebody please help me with this code, I'm trying to delete all rows
that are not dated the current date. My date format in column F is
mm/dd/yyyy, do I need to state that. Thanks

LastRow = Cells(Rows.Count, "F").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If StrComp(Cells(RowNdx, "F"), =Today(), vbTextCompare) < 0 Then
Rows(RowNdx).Delete
End If
Next RowNdx


Paul Mathews

Delete all rows not today
 
Sorry about that, try this modified code:

Sub DelNotTodayRows()
'Deletes rows where the value in column F is not today's date
Dim RowNdx As Long
Dim LastRow As Long

LastRow = Cells(Rows.Count, "F").End(xlUp).Row

For RowNdx = LastRow To 1 Step -1

If Cells(RowNdx, "F").Value = FormatDateTime(Now, vbShortDate) =
False Then
Rows(RowNdx).Delete
End If

Next RowNdx

End Sub

"SITCFanTN" wrote:

Oops Paul, maybe I'm doing this the wrong way...I only want to keep rows with
the current date....this code deletes the current date rows. Should I relook
at this and delete all rows not the current date? What is the best option?

"Paul Mathews" wrote:

Sub DelTodayRows()
'Deletes rows where the value in column F is today's date
Dim RowNdx As Long
Dim LastRow As Long

LastRow = Cells(Rows.Count, "F").End(xlUp).Row

For RowNdx = LastRow To 1 Step -1

If Cells(RowNdx, "F").Value = FormatDateTime(Now, vbShortDate) =
True Then
Rows(RowNdx).Delete
End If

Next RowNdx

End Sub

"SITCFanTN" wrote:

Can somebody please help me with this code, I'm trying to delete all rows
that are not dated the current date. My date format in column F is
mm/dd/yyyy, do I need to state that. Thanks

LastRow = Cells(Rows.Count, "F").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If StrComp(Cells(RowNdx, "F"), =Today(), vbTextCompare) < 0 Then
Rows(RowNdx).Delete
End If
Next RowNdx



All times are GMT +1. The time now is 08:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com