ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code deleting all rows in error (https://www.excelbanter.com/excel-programming/363898-code-deleting-all-rows-error.html)

JOUIOUI

Code deleting all rows in error
 
Here is the code I'm using in an existing macro to keep only rows with
today's date in column F, however it is deleting all rows. My date format in
the column is MM/DD/YYYY. Any help you can provide is appreciated. Thanks
Joyce

Keep only rows dated today

'Dim LastRow As Long
'Dim RowNdx As Long
' 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


Joergen Bondesen

Code deleting all rows in error
 
Hi Joyce

Try this:

Option Explicit

Sub test()
Dim LastRow As Long
Dim RowNdx As Long

Application.ScreenUpdating = False

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

For RowNdx = LastRow To 1 Step -1
If StrComp(Format(Cells(RowNdx, "F"), "MM/DD/YYYY"), _
Format(Now(), "MM/DD/YYYY"), vbBinaryCompare) < _
0 Then

Rows(RowNdx).Delete
End If
Next RowNdx
End Sub


--
Best Regards
Joergen Bondesen


"JOUIOUI" wrote in message
...
Here is the code I'm using in an existing macro to keep only rows with
today's date in column F, however it is deleting all rows. My date format
in
the column is MM/DD/YYYY. Any help you can provide is appreciated.
Thanks
Joyce

Keep only rows dated today

'Dim LastRow As Long
'Dim RowNdx As Long
' 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




Ardus Petus

Code deleting all rows in error
 
Sub Tester()
Dim LastRow As Long
Dim RowNdx As Long
LastRow = Cells(Rows.Count, "F").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "F").Value < Date Then
Rows(RowNdx).Delete
End If
Next RowNdx
End Sub

HTH
--
AP

"JOUIOUI" a écrit dans le message de
news: ...
Here is the code I'm using in an existing macro to keep only rows with
today's date in column F, however it is deleting all rows. My date format
in
the column is MM/DD/YYYY. Any help you can provide is appreciated.
Thanks
Joyce

Keep only rows dated today

'Dim LastRow As Long
'Dim RowNdx As Long
' 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




Mike Fogleman

Code deleting all rows in error
 
Try this:

Dim LastRow As Long
Dim RowNdx As Long
LastRow = Cells(Rows.Count, "F").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "F").Value < Date Then
Rows(RowNdx).Delete
End If
Next RowNdx

Mike F

"JOUIOUI" wrote in message
...
Here is the code I'm using in an existing macro to keep only rows with
today's date in column F, however it is deleting all rows. My date format
in
the column is MM/DD/YYYY. Any help you can provide is appreciated.
Thanks
Joyce

Keep only rows dated today

'Dim LastRow As Long
'Dim RowNdx As Long
' 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 11:12 AM.

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