自定义VBA函数,以在第一次迭代中字符串中断时返回唯一值
我试图创建一个函数,返回任何唯一的范围限制(LOR)测试结果列表。它们在数据中以“”表示。以下代码在指示的位置持续中断。我已经搜索过了,到目前为止,我的逻辑似乎还没有找到问题。。。。谁知道之后会发生什么自定义VBA函数,以在第一次迭代中字符串中断时返回唯一值,vba,excel,Vba,Excel,我试图创建一个函数,返回任何唯一的范围限制(LOR)测试结果列表。它们在数据中以“”表示。以下代码在指示的位置持续中断。我已经搜索过了,到目前为止,我的逻辑似乎还没有找到问题。。。。谁知道之后会发生什么 Public Function LORConc(Data As Range) As String Dim LOR As Range Dim cll As Range Dim tmp As String Dim tmpR As Range For Each cll In Data tmp =
Public Function LORConc(Data As Range) As String
Dim LOR As Range
Dim cll As Range
Dim tmp As String
Dim tmpR As Range
For Each cll In Data
tmp = cll.Value
If InStr(1, tmp, Chr(62)) <> 0 Or InStr(1, tmp, Chr(60)) <> 0 Then
If Not LOR Is Nothing Then
Set LOR = Union(LOR, cll)
Else
LOR = cll ' breaks here, no vba error, just returns #value error to cell
End If
End If
Next
LOR.AdvancedFilter Action:=xlFilterCopy, CopyToRange:=tmpR, Unique:=True
tmp = ""
For Each cll In tmpR
tmp = tmp & "," & cll.Value
Next
If tmp = "" Then
findConc = "No LOR"
Else
findConc = tmp
End If
End Function
公共函数LORConc(数据作为范围)作为字符串
暗淡的颜色范围
暗cll As范围
将tmp设置为字符串
变暗tmpR As范围
对于数据中的每个cll
tmp=cll.值
如果InStr(1,tmp,Chr(62))0或InStr(1,tmp,Chr(60))0,则
如果不是,那就什么都不是了
设置LOR=Union(LOR,cll)
其他的
LOR=cll'在这里中断,没有vba错误,只向单元格返回#值错误
如果结束
如果结束
下一个
LOR.AdvancedFilter操作:=xlFilterCopy,CopyToRange:=tmpR,Unique:=True
tmp=“”
对于tmpR中的每个cll
tmp=tmp&“,”和cll.Value
下一个
如果tmp=”“,则
findConc=“无颜色”
其他的
findConc=tmp
如果结束
端函数
别忘了设置:否则设置LOR=cll
也就是说,此修复后您将遇到其他问题。您似乎将此功能用作自定义项,无法在自定义项中应用筛选。感谢您的快速回复。这是我第一次做一个,所以感谢大家对过滤的关注。我会寻找另一种方式。顺便说一句,我很尴尬没有拿起那条线上缺少的布景。。。啊!(拍额头)