Я использую UDF MEDIANIFS (от Dan Wagner) для фильтрации показаний радиационных значков по имени пользователя и дате (<= дата, указанная пользователем, и> дата 12 месяцами ранее).Дата передается UDF с помощью переменной в моей собственной подпрограмме, но когда переменная varThreshold определена, она отображается только как месяц (IE: вместо 28.07.2008, varThreshold = 7).Это заставляет логические аргументы возвращаться как ложные.VarThreshold определяется данными, анализируемыми функцией Mid.Кажется, он прекращает синтаксический анализ строки, как только она попадает в разделитель «/».Ниже приведены примеры кода.
Мой фрагмент подпрограммы, который вызывает UDF MEDIANIFS:
'-------------Calculate current and past 12 month dates and assign to variables
mth = Month(DateValue("01 " & Range("D2") & " 2019"))
yr = Range("E2")
currDate = DateSerial(yr, mth, 28)
pastDate1 = DateAdd("M", -12, currDate)
pastDate = DateAdd("D", -27, pastDate1)
'-------------Loop to apply past 12 month calculation to each individual Doctor
For i = mdX To mdY
EPmdNme = Range("A" & i)
Range("B" & i) = MEDIANIFS(LdeRng, NameRng, EPmdNme, DateRng, "<=" & currDate, DateRng, ">" & pastDate)
Range("B" & i).NumberFormat = "0.0"
Next I
Здесь currDate = 7/28/18
Соответствующая часть UDF MEDIANIFS:
'Loop through all the range / criteria pairs
For lngCriteriaIdx = LBound(range_and_criteria_pairs) To UBound(range_and_criteria_pairs) Step 2
'Identify the threshold and the operator for use in the criteria phase
Select Case Left(range_and_criteria_pairs(lngCriteriaIdx + 1), 2)
Case Is = "<="
strOperator = "<="
varThreshold = Val(Mid(range_and_criteria_pairs(lngCriteriaIdx + 1), 3))
Case Is = ">="
strOperator = ">="
varThreshold = Val(Mid(range_and_criteria_pairs(lngCriteriaIdx + 1), 3))
Это делает varThreshold = 7
Позже в UDF MEDIANIFS переменная varThreshold сравнивается с переменной Data.В этом случае Data = # 1/1/18 #:
'Criteria phase: check each cell in the passed-in ParamArray against the threshold
With range_and_criteria_pairs(lngCriteriaIdx)
Data = .Cells(lngMedianRowIdx, 1).Value
If VarType(Data) = 7 Then
Data = CDate(.Cells(lngMedianRowIdx, 1).Value)
ElseIf VarType(Data) = 8 Then
Data = UCase(.Cells(lngMedianRowIdx, 1).Value)
Else
Data = .Cells(lngMedianRowIdx, 1).Value
End If
'Check the operator (">=", "<=", "<", ">", "<>", and "=") against the cell
Select Case strOperator
Case Is = "<=" '<~ check if cell is less than or equal to the threshold
If Data <= varThreshold Then
blnAllMatched = True
Else
blnAllMatched = False
End If
Очевидно, что это возвращается как ложное и отрицает весь UDF.
Как я могу получить varThreshold равным currDate, чтобы varThreshold = 7/28/18, чтобы Data <= varThreshold (# 1/1/18 # <= 7/28/18), чтобы я получил "true "result? </p>
varThreshold также используется для фильтрации имени, поэтому оно должно быть определено как вариант.