根据命名范围中的条件进行查找,然后连接结果

我们有一个有趣的公式来弄清楚。

首先,我们计算以下内容,MYDATE需要在两个date之间。 REGISTER.DT和EXIT.DT都是命名范围A:A和B:B,MYDATE是命名范围,指向C1。

= SUMPRODUCT( – (REGISTER.DT <=数值指明MyDate)*(EXIT.DT> =数值指明MyDate))

另一个例子,有更多的标准(有时最多5个标准)

= SOMPRODUCT( – (AANM.DT> = DT.START) (AANM.DT <= DT.EIND) (TYPE.TXT = I8))

现在的问题。 上面的formule返回2(所以它find两个date)

我们现在想要以串联的string查找并显示这些date

我一直在摆弄我在网上find的VBA函数StringConcat,但是我不会跳过零(全部转换为string),但也可以理解命名的范围。

任何人都有提示? 或可以工作的matrixfunction查找?

非常感谢

这是用户定义的function,将根据您的devise工作。 在前两个参数中input两个匹配数组,然后在第三个参数中input关键date。 您将收回注册date列表,标记持有该关键date的范围的开始:

Option Explicit Function DateCAT(RegisterRng As Range, ExitRng As Range, MyDt As Date) As String Dim DtARR As Variant, D As Long If RegisterRng.Cells.Count <> ExitRng.Cells.Count Then DateCAT = "date ranges do not match" Exit Function End If DtARR = Union(RegisterRng, ExitRng) For D = LBound(DtARR) To UBound(DtARR) If DtARR(D, 1) <= MyDt And DtARR(D, 2) >= MyDt Then DateCAT = DateCAT & ", " & DtARR(D, 1) End If Next D If DateCAT = "" Then DateCAT = "none" Else DateCAT = Mid(DateCAT, 3, Len(DateCAT)) End If End Function 

= DATECAT(REGISTER.DT,EXIT.DT,MYDATE)

在这里输入图像说明

顺便说一句,我用于REGISTER.DT和EXIT.DT的公式是dynamic的。

= OFFSET(Sheet1中$ A $ 1 ,,, COUNTA(Sheet1中$ A:!$ A))

= OFFSET(Sheet1中$ B $ 1 ,,, COUNTA(Sheet1中$ B:!$ B))

============================这个版本就像COUNTIFS(),你把范围从第一个返回,然后列出值对…一个范围,然后对该范围进行testing,然后select另一个范围和testing,总共达到5个。

= DATECAT(值,TstRng1,Test1,OptTstRng2,OptTest2,OptTstRng3,OptTest3)

 Option Explicit Function DateCAT(RegisterRng As Range, RNG1 As Range, TST1 As String, _ Optional RNG2 As Range, Optional TST2 As String, _ Optional RNG3 As Range, Optional TST3 As String, _ Optional RNG4 As Range, Optional TST4 As String, _ Optional RNG5 As Range, Optional TST5 As String) As String Dim D As Long, Bad As Boolean, i As Long D = RegisterRng.Cells.Count If RNG1.Cells.Count <> D Then Bad = True If Not RNG2 Is Nothing Then If RNG2.Cells.Count <> D Then Bad = True If Not RNG3 Is Nothing Then If RNG3.Cells.Count <> D Then Bad = True If Not RNG4 Is Nothing Then If RNG4.Cells.Count <> D Then Bad = True If Not RNG5 Is Nothing Then If RNG5.Cells.Count <> D Then Bad = True If Bad Then DateCAT = "data ranges do not match" Exit Function End If For i = 1 To RNG1.Cells.Count If WorksheetFunction.CountIf(RNG1.Cells(i), TST1) = 0 Then Bad = True If Not RNG2 Is Nothing Then If WorksheetFunction.CountIf(RNG2.Cells(i), TST2) = 0 Then Bad = True If Not RNG3 Is Nothing Then If WorksheetFunction.CountIf(RNG3.Cells(i), TST3) = 0 Then Bad = True If Not RNG4 Is Nothing Then If WorksheetFunction.CountIf(RNG4.Cells(i), TST4) = 0 Then Bad = True If Not RNG5 Is Nothing Then If WorksheetFunction.CountIf(RNG5.Cells(i), TST5) = 0 Then Bad = True If Not Bad Then DateCAT = DateCAT & ", " & RegisterRng.Cells(i).Value Bad = False Next i If DateCAT = "" Then DateCAT = "none" Else DateCAT = Mid(DateCAT, 3, Len(DateCAT)) End If End Function 

重要提示:当检查一个已命名的范围(一个单元格,1值)时,需要inputTST1等作为操作">"&MYCELL和命名范围: ">"&MYCELL

在这里输入图像说明