【发布时间】:2021-12-26 05:59:42
【问题描述】:
| Column A | Column B |
|---|---|
| 1 | |
| 2 | 1 |
| 3 | 1 |
| 4 | |
| 5 | 1,4 |
| etc |
试图弄清楚如何搜索 A 列中的数字是否存在于 B 列中的任何位置。
到目前为止我已经尝试过:
=IF(ISNUMBER(SEARCH(A2,B:B)),"YES","NO") which returns #spill
Function CheckOne(rng As Range, chkValue As Long) As Boolean
Dim n
For Each n In Split(rng.Value, ",")
If CLng(n) = chkValue Then
CheckOne = True
Exit For
End If
Next n
End Function
Function CommaSeparatedListContains(ByVal csv As String, ByVal v As String, _
Optional ByVal delimiter As String = ",") As Boolean
Dim i As Long
Dim splitCsv() As String
splitCsv = Split(csv, delimiter)
CommaSeparatedListContains = False
For i = LBound(splitCsv) To UBound(splitCsv)
If splitCsv(i) = v Then
CommaSeparatedListContains = True
Exit Function
End If
Next i
End Function
这也不起作用,因为我得到了#VALUE!错误
我怀疑这是因为我要查找的值在 B 列中出现多次。
我在这里做错了什么?
【问题讨论】:
-
绝对不需要 VBA。由于这些问题经常被问到,因此对 SO 进行良好搜索应该会产生结果。在我的手机上,但我相信有人可以找到重复的。提示,您需要对结果求和,不要溢出它们。并考虑误报,用逗号括起来值
标签: excel vba user-defined-functions