Hello,
I am having a very strange issue where I select two dates (in the format mm/dd/yyyy hh:mm:ss) and a table is generated with data from the Start Date and End Date. There is a 'data storage' sheet, Sheet4, that has all potential dates to choose from in Row 4. There are 5 columns of data for each date. Data storage table example below:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]10/25/2019 13:52:45[/TD]
[TD]10/25/2019 13:52:45[/TD]
[TD]10/25/2019 13:52:45[/TD]
[TD]10/25/2019 13:52:45[/TD]
[TD]10/25/2019 13:52:45[/TD]
[TD]10/28/2019 08:33:02[/TD]
[TD]10/28/2019 08:33:02[/TD]
[TD]10/28/2019 08:33:02[/TD]
[TD]10/28/2019 08:33:02[/TD]
[TD]10/28/2019 08:33:02[/TD]
[/TR]
[TR]
[TD]Category 1[/TD]
[TD]Category 2[/TD]
[TD]Category 3[/TD]
[TD]Category 4[/TD]
[TD]Category 5[/TD]
[TD]Category 1[/TD]
[TD]Category 2[/TD]
[TD]Category 3[/TD]
[TD]Category 4[/TD]
[TD]Category 5[/TD]
[/TR]
[TR]
[TD]Data 1[/TD]
[TD]Data 2[/TD]
[TD]Data 3[/TD]
[TD]Data 4[/TD]
[TD]Data 5[/TD]
[TD]Data 1[/TD]
[TD]Data 2[/TD]
[TD]Data 3[/TD]
[TD]Data 4[/TD]
[TD]Data 5[/TD]
[/TR]
</tbody>[/TABLE]
Below is part of the code for generating the consolidated table on Sheet5 (data comparison between the two dates):
It seems like if I select any date that has been generated today, the code fails on any step with the EndDate variable, even if the date and associated data is on Sheet4. For example, it will fail on the second MsgBox and, if the MsgBox's are commented out, it will fail when the recEndColumn line is executed. The failure in both cases is "Run-time error '91': Object variable or With block variable not set."
Anything regarding the StartDate variable is done successfully and the correct cell address for the first instance of the date is given for the MsgBox and the correct column number is generated as well.
This is code developed by someone else, and the file is very complicated, so in the short-term I just want a quick solution to this issue, but am planning on redesigning this in the future.
Thank you for any help!
I am having a very strange issue where I select two dates (in the format mm/dd/yyyy hh:mm:ss) and a table is generated with data from the Start Date and End Date. There is a 'data storage' sheet, Sheet4, that has all potential dates to choose from in Row 4. There are 5 columns of data for each date. Data storage table example below:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]10/25/2019 13:52:45[/TD]
[TD]10/25/2019 13:52:45[/TD]
[TD]10/25/2019 13:52:45[/TD]
[TD]10/25/2019 13:52:45[/TD]
[TD]10/25/2019 13:52:45[/TD]
[TD]10/28/2019 08:33:02[/TD]
[TD]10/28/2019 08:33:02[/TD]
[TD]10/28/2019 08:33:02[/TD]
[TD]10/28/2019 08:33:02[/TD]
[TD]10/28/2019 08:33:02[/TD]
[/TR]
[TR]
[TD]Category 1[/TD]
[TD]Category 2[/TD]
[TD]Category 3[/TD]
[TD]Category 4[/TD]
[TD]Category 5[/TD]
[TD]Category 1[/TD]
[TD]Category 2[/TD]
[TD]Category 3[/TD]
[TD]Category 4[/TD]
[TD]Category 5[/TD]
[/TR]
[TR]
[TD]Data 1[/TD]
[TD]Data 2[/TD]
[TD]Data 3[/TD]
[TD]Data 4[/TD]
[TD]Data 5[/TD]
[TD]Data 1[/TD]
[TD]Data 2[/TD]
[TD]Data 3[/TD]
[TD]Data 4[/TD]
[TD]Data 5[/TD]
[/TR]
</tbody>[/TABLE]
Below is part of the code for generating the consolidated table on Sheet5 (data comparison between the two dates):
Code:
Dim StartDate, EndDate As String
Dim recStartColumn, recEndColumn As Long
Sheet5.Range("B7:L58").ClearContents
StartDate = Sheet5.Range("D1").Text
EndDate = Sheet5.Range("D2").Text
MsgBox Sheet4.Rows(4).Find(StartDate, LookIn:=xlValues).Address 'Displays cell $CIR$4 correctly
MsgBox Sheet4.Rows(4).Find(EndDate, LookIn:=xlValues).Address 'Fails (Error 91). Should display $CIW$4.
recStartColumn = Sheet4.Rows(4).Find(StartDate, LookIn:=xlValues).Column 'Correctly finds Column 2280
recEndColumn = Sheet4.Rows(4).Find(EndDate, LookIn:=xlValues).Column 'Fails (Error 91). Should be Column 2285
Anything regarding the StartDate variable is done successfully and the correct cell address for the first instance of the date is given for the MsgBox and the correct column number is generated as well.
This is code developed by someone else, and the file is very complicated, so in the short-term I just want a quick solution to this issue, but am planning on redesigning this in the future.
Thank you for any help!