Good day,
I'm looking for some guidance as to why a piece of code I have does not function as expected. The code ultimately opens multiple .csv files, then looks for certain date values in Column E and decides whether to delete the row or not. The code to delete the row works fine if I run it as stand alone like below:
Sub test()
Dim LR As Long
Application.ScreenUpdating = False
LR = ActiveSheet.Range("E" & Rows.Count).End(xlUp).Row
For r = LR To 2 Step -1
If ((Weekday(Date) >= 3 And Weekday(Date) <= 6 And Range("E" & r).Value <> Date - 1) Or (Weekday(Date) = 2 And _
Range("E" & r).Value <> Date - 3)) Then
Rows(r).Delete
Application.ScreenUpdating = True
End If
Next r
End Sub
However, when I add it to the code that looks through a certain folder for multiple .csv it does not complete the operation. The code is below:
Public Sub Setup1()
Dim StrFile As String
Dim LR As Long
StrFile = Dir("C:\Users\admi n\Downloads\*.csv")
While StrFile <> ""
Workbooks.Open fileName:=StrFile
Application.ScreenUpdating = False
LR = ActiveSheet.Range("E" & Rows.Count).End(xlUp).Row
For r = LR To 2 Step -1
If (Range("E" & r).Value <> Date - 1) Then
Rows(r).Delete
Application.ScreenUpdating = True
End If
Next r
StrFile = Dir
Wend
End Sub
Can anyone perhaps explain to me why this does not work?
Thanks
I'm looking for some guidance as to why a piece of code I have does not function as expected. The code ultimately opens multiple .csv files, then looks for certain date values in Column E and decides whether to delete the row or not. The code to delete the row works fine if I run it as stand alone like below:
Sub test()
Dim LR As Long
Application.ScreenUpdating = False
LR = ActiveSheet.Range("E" & Rows.Count).End(xlUp).Row
For r = LR To 2 Step -1
If ((Weekday(Date) >= 3 And Weekday(Date) <= 6 And Range("E" & r).Value <> Date - 1) Or (Weekday(Date) = 2 And _
Range("E" & r).Value <> Date - 3)) Then
Rows(r).Delete
Application.ScreenUpdating = True
End If
Next r
End Sub
However, when I add it to the code that looks through a certain folder for multiple .csv it does not complete the operation. The code is below:
Public Sub Setup1()
Dim StrFile As String
Dim LR As Long
StrFile = Dir("C:\Users\admi n\Downloads\*.csv")
While StrFile <> ""
Workbooks.Open fileName:=StrFile
Application.ScreenUpdating = False
LR = ActiveSheet.Range("E" & Rows.Count).End(xlUp).Row
For r = LR To 2 Step -1
If (Range("E" & r).Value <> Date - 1) Then
Rows(r).Delete
Application.ScreenUpdating = True
End If
Next r
StrFile = Dir
Wend
End Sub
Can anyone perhaps explain to me why this does not work?
Thanks