我有两张桌子:(1)列出临床医生和他们的休假日期,(2)列出诊所和诊所关闭的日期。
我想确定一个诊所因临床医生的休假时间而关闭的频率(由临床医生在同一天的休假时间确定)。
棘手的部分是将临床医生与他们的诊所联系起来。诊所通常只包含临床医生姓名的一部分,诊所也随机命名。
我试图使用if(countif)> 0功能,在临床医生的名字周围设置一个通配符( Clinician ),以表示由于临床医生不在,诊所是否已关闭,但没有成功。
提前感谢您提供的任何指导!
以下是表格的示例:
答案 0 :(得分:0)
我不确定非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
附件是结果的截图,包括数字和公式。