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
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