Comparing Dates

Rocky0201

Active Member
Joined
Aug 20, 2009
Messages
278
Hi…
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p> </o:p>
I am comparing two dates— the first date is the current system date and the second date is in column G starting at row 2 through row x. I need to determine if the system date is past the date in Gx or if the system date is within a “configurable” number of business days to the date in Gx. During run-time, I am receiving a Type mismatch on the Evaluate statement.
<o:p> </o:p>
The code below:
<o:p> </o:p>
RRptHD() – an array (Long) that has the column information.
RRptHDC7 – is the offset into the array that points to the column number that is stored in the array.
At debug: this value is, as expected 7 for the column number.
<o:p> </o:p>
OIRGroupCount() is an array where I build my counts for use of displaying later.
<o:p> </o:p>
RPTDueDate() an array (Long) that has the row and column information of a configurable date in the sheet “Lists”.
RptDueDateR1 and RptDueDateC1 are offsets into the array where at the offset, the row number and column number of the “configurable” number of days is store in the sheet “Lists”.
At debug: the values are, as expected RptDueDateR1 is 1 for the row number, RptDueDateC1 is 17 for the column number.
<o:p> </o:p>
If Evaluate("NETWORKDAYS(Now()," & Cells(i, RRptHD(RRptHDC7)) & ")") < 1 Then
OIRGroupCount(2) = OIRGroupCount(2) + 1
Else
If Evaluate("NETWORKDAYS(Now()," & Cells(i, RRptHD(RRptHDC7)) & ")") <= Sheets("Lists").Cells(RptDueDate(RptDueDateR1), RptDueDate(RptDueDateC1)) Then
OIRGroupCount(1) = OIRGroupCount(1) + 1
End If
End If<o:p></o:p>

<o:p> </o:p>
If there is a different way of doing a Now() and/or Networkdays, please let me know..
<o:p> </o:p>
Thanks for the help…
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Are you sure the problem lies with the dates and/or the comparison?

Have you checked out your arrays/variables?
 
Upvote 0
I did Norie... The arrays and variables check out... If I were to remove the "If" and remove the "Then" from the Evaluate statement, i do not get any run-time errors. with this in mind, how do I test the results of the statement? I tried Varibale = Evaluate..., String = Evaluate... If Evaluate .... = True Then...

All of those cause a type mismatch.

Any help would be wonderful Norie...
 
Upvote 0
I don't use either NETWORKDAYS or Evaluate much, the former neither on a worksheet or in code, so I can't do much testing.:)

But my next thought was does the actual formula work?

eg could it be throwing an error?

Is it even possible to use NETWORKDAYS with Evaluate? It probably is but stranger things have been know to happen.:rolleyes:
 
Upvote 0
This is what I have in a cell in one of my sheets:

=IF(NETWORKDAYS(NOW(),G110)<1,1,IF(NETWORKDAYS(NOW(),G110)<=3,2,""))

This works perfectly.

I am trying to do the same thing in vb as this is the last calulaction that i need to perfrom to eliminate any formula's in my sheet and eliminate the sheet altogether. All of my other "count gathering" work is done in vb code. The other nice thing is I do not have to be concerned with having a formula in a fixed number of rows since vb allows me to "do until" the last row of the sheet.

On other thing for me to try-- It just occurred to me that the first cell I am referrencing in my cells(i, ...) is a null. I will put a value in that cell to see if it makes the run-time work...
 
Upvote 0
That was the problem Norie... the test did not like a null in the cell that I am testing. No more run-time error. Now I'll work on my logic...

Thanks so much Norie...
 
Upvote 0
Well I'm afraid I can't help you much further - I rarely if ever use NETWORKDAYS and I'm not about to install the Analysis Toolpak Add-In.

I do know however that you can use the functions from the add-in via VBA just like you can use other functions.

You just need to set a reference to the correct library which I think is called something like atpvbaen.xla.

To access that you'll need to have the Analysis... VBA Add-In installed.

I've no idea if that's going to help but it might be worth a punt.:)
 
Upvote 0
you asked about now() and something different in VB. Do you need the date to stay static or change each time the sheet is opened?
 
Upvote 0
Thanks texasalynn...

now() needs to represent the current system date everytime the code is executed. That would be at sheet opened and whenever a specific cell is doubleclicked.

I have gotten this far:

If Cells(i, RRptHD(RRptHDC7)) <> "" Then
If Evaluate("NetworkDays(Now(), " & Cells(i, RRptHD(RRptHDC7)) & ")") < 1 Then
OIRGroupCount(2) = OIRGroupCount(2) + 1
Else
If Evaluate("NETWORKDAYS(Now()," & Cells(i, RRptHD(RRptHDC7)) & ")") <= Sheets("Lists").Cells(RptDueDate(RptDueDateR1), RptDueDate(RptDueDateC1)) Then
OIRGroupCount(1) = OIRGroupCount(1) + 1
End If
End If
End If

My problem is-- when i stop at the first if statement and then step into, the result from the Evaluate is -28633. I am not certain where this is coming from.

Any thoughts?
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top