find if row checkin date is within30 days of previous rows checkoutdate.

S

steve1040

All I have the following function which I got from here and it is very
slow but I thought it was working until I noticed that sometimes the
first occurance of a name is still appearing as within 30 days. What
is causing this?


Function within30(Name As Range, NameRng As Range, Admit As Range,
Discharge As Range) As String
Application.Volatile
Dim NameCount As Long
Dim ChkOut As Long
Dim ChkIn As Long
Dim f As Range
NameCount = Application.WorksheetFunction.CountIf(NameRng, Name)
If NameCount = 1 Then
within30 = ""
Exit Function
End If
For n = 1 To NameCount
For r = Name.Row + 1 To NameRng.Rows.Count - 1
Debug.Print r
If Cells(r, Name.Column) = Name Then
ChkOut = Cells(Name.Row, Discharge.Column)
ChkIn = Cells(r, Admit.Column)
If ChkIn - ChkOut <= 30 Then
within30 = "X"
Exit For
End If
Set Name = Cells(r, Name.Column)
End If
Next
Next
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top