Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 718
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting rows in two columns with a code in visual basic Ruben Excel Discussion (Misc queries) 5 August 27th 08 09:10 AM
Deleting rows based upon Error conditions JEff Excel Programming 1 December 28th 04 09:55 PM
Help with Chip Pearson's Code for Deleting Blank Rows Rashid Khan Excel Programming 6 June 30th 04 08:53 PM
VBA code for Deleting rows by verification hoffman3 Excel Programming 4 June 3rd 04 08:55 PM
visual basic macro code for deleting referenced rows Frank Kabel Excel Programming 0 January 28th 04 10:05 PM


All times are GMT +1. The time now is 06:44 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"