Here is the current macro I am working with.:
I am trying to change an Excel file from the bottom-up until I find a date that is not today's date (where today means the day you look at the file and not the day this forum post is posted) in which case, I just want the copying process to stop but I am not able to successfully compare the dates.
The compiler says:
Run-time error '1004':
Application-defined or object-defined error
and suggests that the following line is at fault.:
Any help in getting the loop and date comparison to work well would be greatly appreciated!
Code:
Sub MySub()
Dim strColumn As String
Dim currentRow As Integer
Dim todayDate As Date
Dim ws As Worksheet
Set ws = Workbooks("file_I_am_getting_data_from.xlsm").Sheets(1) 'I am getting the data from the larger file
todayDate = Format(Date, "dd/mm/yyyy")
currentRow = 3458
'Copies over data that is relevant to this day (=today) from the larger file to smaller one
Do Until ws.Cells(row, 1).Value <> todayDate
ws.Range("A" & currentRow & ":" & "X" & currentRow).Copy ThisWorkbook.Worksheets(1).Range("AO2")
currentRow = currentRow - 1
Loop
'ws.Range("A" & currentRow & ":" & "X" & currentRow).Copy ThisWorkbook.Worksheets(1).Range("AO2")
End Sub
The compiler says:
Quote:
Run-time error '1004':
Application-defined or object-defined error
Code:
Do Until ws.Cells(row, 1).Value <> todayDate