|
函数改成这样就可以直接引用了。比如在单元格中D2直接输入=getchoice(C2),然后下拉就行了。- Public Function GetChoice(xrng As Range) As String
- With Sheet1
- r = .[a65536].End(3).Row
- arr = .Range("a1:c" & r)
- c = xrng.Value: c1 = xrng.Offset(1, 0).Value: xstr = "" 'c为C列当前行字符,c1为C列下一行字符
- For j = 2 To UBound(arr)
- If InStr(c, "<") > 0 Then '如果c包含“<”(小于某数)
- jdg = Val(Replace(c, "<", "")) '提取“<”前面的数字作为判断“小于”的数值
- If arr(j, 2) < jdg Then xstr = xstr & arr(j, 1) & "(" & arr(j, 2) & ") " '如果条件满足,字符累加
- End If
-
- If InStr(c, "-") > 0 And InStr(c1, "-") > 0 Then ' 如果c包含“-”,c1包含“-”(界于两数之间)
- jdg = Val(c): jdg1 = Val(c1)
- If jdg <= arr(j, 2) And arr(j, 2) < jdg1 Then xstr = xstr & arr(j, 1) & "(" & arr(j, 2) & ") "
- End If
-
- If InStr(c, "-") > 0 And InStr(c1, "-") = 0 Then '如果c包含“-”,c1不包含“-”(大于某数)
- jdg = Val(c)
- If jdg <= arr(j, 2) Then xstr = xstr & arr(j, 1) & "(" & arr(j, 2) & ") "
- End If
-
- Next
- GetChoice = Trim(Replace(xstr, "(.", "(0.")) '因为小数如0.23的“0”不显示,所以遇到“(.”就替代成“(0.”
- End With
- End Function
复制代码 |
|