我有两个表格:(1)列出临床医生及其休假日期;(2)列出诊所和诊所关闭的日期。
我想确定一家诊所因临床医生的休假时间而关闭的频率(由同一天的临床医生休假时间决定)。
棘手的部分是把临床医生和他们的诊所联系起来。这些诊所通常只包含临床医生名字的一部分,而且诊所的名字非常随意。
我尝试使用一个if(countif )>0函数,在临床医生的名字周围设置一个通配符(临床医生),以表示一个诊所是否因为临床医生的离去而关闭,但没有成功。
谢谢您能提供的任何指导!
以下是表的一个示例:
发布于 2017-03-21 15:03:17
我不确定是否有一种非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附件是结果的截图,包括数字和公式。


https://stackoverflow.com/questions/42929139
复制相似问题