Hoping someone might have a clue if there is anything I can do to work around the problem I am having. It might be difficult to add the code in I am using as it is so big.
I have a table with calendar dates in the first column. They are all in dd/mm/yyyy format. In VBA I want to search for a date and find the row number within the calendar using the following;
FirstRow = Workbooks(WorkbookSelected.Name).Sheets("Tables").Columns(1).Find(ConfirmedDate, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, LookAt:=xlWhole).Row
The Confirmed Date is stored as a Date variable, taken from the calendar as well, but it gets days added to it. I am searching in two different workbooks to find the FirstRow. If both workbooks are in the same application/instance of excel then this code works fine.
But if I open the 2nd workbook in a new instance of excel, it errors because the date isn't found. Something is happening with the date in the 2nd application. If I use format(ConfirmedDate, "dd/mm/yyyy")
it will find it in the 2nd workbook. But that code won't work in the original workbook. Similar code to above, but just referencing the Excel Instance it needs to look into. I get the Runtime Error 91 when it won't find it.
FirstRow = ExcelInstanceSelected.Workbooks(WorkbookSelected.Name).Sheets("Tables").Columns(1).Find(ConfirmedDate, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, LookAt:=xlWhole).Row
FirstRow = ExcelInstanceSelected2.Workbooks(2ndWorkbookSelected.Name).Sheets("Tables").Columns(1).Find(ConfirmedDate, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, LookAt:=xlWhole).Row
I am trying to find a way to find the date in the calendar regardless of which excel application I am using. I have tried opening the workbook with the local set to true (doesn't help). I have tried combinations of format, cdate, cdbl, lookin:=xlformulas. Nothing will work with both workbooks.
It is driving me nuts. I can only assume that the .find in the 2nd workbook is changing the format of the stored ConfirmedDate to the US format of m/dd/yyyy. I just can't find a way to ensure both dates can be formatted to dd/mm/yyyy regards of how they start.
Many thanks for any help.
Cel