I have a macro that I wrote below that is not working like I expected. I do not get a runtime error, but the outcome is not what I desired.
I have 2 files; 1 main macro file and a second file that this macro opens.
I am trying to delete rows in Col L of the 2nd file based on a value in the first column.
What I wanted is for the user to input a date in the main macro file. Then after they click run the 2nd file opens and the macro deletes all rows in the file which are < the input date.
My macro seems to run fine, but no rows ever get deleted. Am I missing something here now? Thanks in advance for any help.
Sub Test()
Workbooks.Open Filename:= _
"C:\Desktop\CMS Reports\DP Export.xlsx"
Windows("DP Export.xlsx").Activate
Columns("L:L").Select
Selection.NumberFormat = "m/d/yy;@"
Dim endrow As Integer
On Error Resume Next
endrow = Sheets("DP Export").Range("L1000").End(xlUp).Row
Searchdate = [CMS Report Macro.xlsm].Range("F6").Value
For i = endrow To 1 Step -1
tdate = Cells(i, 6).Value
If IsDate(tdate) = True And tdate < Searchdate Then
Cells(i, 6).EntireRow.Delete
End If
Next i
End Sub
I have 2 files; 1 main macro file and a second file that this macro opens.
I am trying to delete rows in Col L of the 2nd file based on a value in the first column.
What I wanted is for the user to input a date in the main macro file. Then after they click run the 2nd file opens and the macro deletes all rows in the file which are < the input date.
My macro seems to run fine, but no rows ever get deleted. Am I missing something here now? Thanks in advance for any help.
Sub Test()
Workbooks.Open Filename:= _
"C:\Desktop\CMS Reports\DP Export.xlsx"
Windows("DP Export.xlsx").Activate
Columns("L:L").Select
Selection.NumberFormat = "m/d/yy;@"
Dim endrow As Integer
On Error Resume Next
endrow = Sheets("DP Export").Range("L1000").End(xlUp).Row
Searchdate = [CMS Report Macro.xlsm].Range("F6").Value
For i = endrow To 1 Step -1
tdate = Cells(i, 6).Value
If IsDate(tdate) = True And tdate < Searchdate Then
Cells(i, 6).EntireRow.Delete
End If
Next i
End Sub