首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当一个限定符需要灵活性来确定匹配是否正确时,判断一个案例是否符合两个限定符

当一个限定符需要灵活性来确定匹配是否正确时,判断一个案例是否符合两个限定符
EN

Stack Overflow用户
提问于 2017-03-21 13:53:28
回答 1查看 44关注 0票数 0

我有两个表格:(1)列出临床医生及其休假日期;(2)列出诊所和诊所关闭的日期。

我想确定一家诊所因临床医生的休假时间而关闭的频率(由同一天的临床医生休假时间决定)。

棘手的部分是把临床医生和他们的诊所联系起来。这些诊所通常只包含临床医生名字的一部分,而且诊所的名字非常随意。

我尝试使用一个if(countif )>0函数,在临床医生的名字周围设置一个通配符(临床医生),以表示一个诊所是否因为临床医生的离去而关闭,但没有成功。

谢谢您能提供的任何指导!

以下是表的一个示例:

休假时间与门诊取消

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-21 15:03:17

我不确定是否有一种非VBA的方法,所以我创建了一个毫无疑问可以改进的函数,但是我认为它得到了您所提供的输入所期望的结果。

基本上,该功能将采用诊所关闭的日期范围和诊所的名称(所有这些都是一个单一的参数)。该功能还将临床医生和休假日期作为单独的参数。该功能将循环通过诊所关闭,并确定该公式中的临床医生是否是关闭诊所的部分匹配,在临床医生离开的日期。

代码语言:javascript
运行
复制
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

附件是结果的截图,包括数字和公式。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42929139

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档