当一个限定词需要灵活判断匹配是否正确时,判断一个案例是否满足两个限定词
Determing whether a case meets two qualifiers when one qualifier requires flexibility in determing whether the match is correct
我有两个表格:(1) 列出临床医生及其休假日期,(2) 列出诊所及其关闭日期。
我想确定诊所因临床医生的休假时间而关闭的频率(由同一天临床医生的休假时间确定)。
棘手的部分是将临床医生与其诊所联系起来。诊所通常只包含临床医生姓名的一部分,而且诊所的命名非常随意。
我尝试使用 if(countif )>0 函数和围绕临床医生姓名设置的通配符 (Clinician) 来表示诊所是否因以下原因而关闭一位临床医生走了,但还没有成功。
提前感谢您提供的任何指导!
以下是表格示例:
Leave Time versus Clinic Cancellations
我不确定 non-VBA 方法可以做到这一点,所以我创建了一个毫无疑问可以改进的函数,但我认为它会根据您提供的输入得到您期望的结果.
基本上,该函数将采用诊所关闭的日期范围和诊所的名称(全部作为一个参数)。该函数还将临床医生和离开日期作为单独的参数。该函数将遍历诊所关闭并确定公式中的临床医生是否与临床医生休假日期的关闭诊所部分匹配。
Public Function Closed(rngClinic, rngClinician, rngClinicianLeave)
'function loops through each clinic and clinic close date
'to determine if the clinic name contains the clinician who took leave
'on the same date the clinic is closed.
'If so, add this as a closure and continue counting
'until all clinics have been checked.
Dim Clinic() As Variant 'This stores the range of clinic names and dates they were closed
Dim Clinician As String 'just the clinician name on the date of elave
Dim ClinicianLeave As Date ' the leave date of the clinician
Dim iCounter As Integer 'this counts the # of closures given a clinician and a leave date
Dim iClinicCount As Integer 'this is just a count of the # of loops that need to occur
With Excel.Application
Clinic = .Transpose(rngClinic)
Clinician = rngClinician
ClinicianLeave = rngClinicianLeave
iCounter = 0
iClinicCount = .CountA(Clinic) / 2
For x = LBound(Clinic) To iClinicCount
If Clinic(1, x) = ClinicianLeave And Clinic(2, x) Like "*" & Clinician & "*" Then
iCounter = iCounter + 1
End If
Next
End With
Closed = iCounter
End Function
附件是结果的屏幕截图,包括数字和公式。
我有两个表格:(1) 列出临床医生及其休假日期,(2) 列出诊所及其关闭日期。
我想确定诊所因临床医生的休假时间而关闭的频率(由同一天临床医生的休假时间确定)。
棘手的部分是将临床医生与其诊所联系起来。诊所通常只包含临床医生姓名的一部分,而且诊所的命名非常随意。
我尝试使用 if(countif )>0 函数和围绕临床医生姓名设置的通配符 (Clinician) 来表示诊所是否因以下原因而关闭一位临床医生走了,但还没有成功。
提前感谢您提供的任何指导!
以下是表格示例:
Leave Time versus Clinic Cancellations
我不确定 non-VBA 方法可以做到这一点,所以我创建了一个毫无疑问可以改进的函数,但我认为它会根据您提供的输入得到您期望的结果.
基本上,该函数将采用诊所关闭的日期范围和诊所的名称(全部作为一个参数)。该函数还将临床医生和离开日期作为单独的参数。该函数将遍历诊所关闭并确定公式中的临床医生是否与临床医生休假日期的关闭诊所部分匹配。
Public Function Closed(rngClinic, rngClinician, rngClinicianLeave)
'function loops through each clinic and clinic close date
'to determine if the clinic name contains the clinician who took leave
'on the same date the clinic is closed.
'If so, add this as a closure and continue counting
'until all clinics have been checked.
Dim Clinic() As Variant 'This stores the range of clinic names and dates they were closed
Dim Clinician As String 'just the clinician name on the date of elave
Dim ClinicianLeave As Date ' the leave date of the clinician
Dim iCounter As Integer 'this counts the # of closures given a clinician and a leave date
Dim iClinicCount As Integer 'this is just a count of the # of loops that need to occur
With Excel.Application
Clinic = .Transpose(rngClinic)
Clinician = rngClinician
ClinicianLeave = rngClinicianLeave
iCounter = 0
iClinicCount = .CountA(Clinic) / 2
For x = LBound(Clinic) To iClinicCount
If Clinic(1, x) = ClinicianLeave And Clinic(2, x) Like "*" & Clinician & "*" Then
iCounter = iCounter + 1
End If
Next
End With
Closed = iCounter
End Function
附件是结果的屏幕截图,包括数字和公式。