Hi,
How do I copy date data retaining its number format?
I have written a matching algorithm which sorts by both an unique identifier and date. If a record falls outside the defined window it is deleted. For a time, the code performed as expected, copying all data from source documents to a Worksheet in another Workbook and then executing. However, one day it just stopped working and began deleting all records. Debugging ensued. Eventually, I found that the date data copied from source documents was not a number (probably a string but unclear) despite originally being of the usual Gregorian kind. I suspect the Date function is not recognising these string dates because they are not numbers.
Please help clarify what is happening and how to fix it.
How do I copy date data retaining its number format?
Rich (BB code):
Dim Sourceworkbook1 As Workbook
Set Sourceworkbook1 = Workbooks.Open("[File path & name]")
Application.ScreenUpdating = False
Sourceworkbook1.Sheets("[tab name]").Copy After:=ThisWorkbook.Sheets("[tabname]")
I have written a matching algorithm which sorts by both an unique identifier and date. If a record falls outside the defined window it is deleted. For a time, the code performed as expected, copying all data from source documents to a Worksheet in another Workbook and then executing. However, one day it just stopped working and began deleting all records. Debugging ensued. Eventually, I found that the date data copied from source documents was not a number (probably a string but unclear) despite originally being of the usual Gregorian kind. I suspect the Date function is not recognising these string dates because they are not numbers.
Please help clarify what is happening and how to fix it.