vba - 以没有编译错误结束。我正在比较两个字符串
问题描述
Function CompareTwo(txt As String, txt2 As String, _
Optional delim As String = ";") As String
Dim a, b
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
For Each a In Split(txt, delim)
For Each b In Split(txt2, delim)
If Trim(a).contains(Trim(b)) Then .Add Trim(a), Nothing
Next b
Next a
If .Count > 0 Then
CompareTwo = Join(.keys, delim)
End With
End Function
解决方案
你错过了一个 End If。
Function CompareTwo(txt As String, txt2 As String, _
Optional delim As String = ";") As String
Dim a, b
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
For Each a In Split(txt, delim)
For Each b In Split(txt2, delim)
' what is 'contains' ?
If Trim(a).contains(Trim(b)) Then .Add Trim(a), Nothing
' maybe this is better
If cbool(instr(1, Trim(a), Trim(b), vbtextcompare)) Then .Add Trim(a), Nothing
Next b
Next a
If .Count > 0 Then
CompareTwo = Join(.keys, delim)
end if '<~~ here
End With
End Function
推荐阅读
- bash - 当旧的 Git 仍然存在时如何从头开始新的 Git
- xamarin - 完成后如何禁用Syncfusion的自动完成移动到下一个条目?
- java - SignalR(ASP .Net)-“ConnectionId 的格式不正确”-使用自己的 Java Websocket 客户端的 websocket 问题
- python - 将带有硬编码换行符的字符串转换为python中的矩阵
- python - 在 pandas 数据框中找到第一次出现的值(从值列表中)并返回该行的索引
- python - pip install pyinstaller 失败,无法连接到我没有任何代理设置的代理
- sql - Oracle SQL - 如何比较同一张表中两组之间的行数?
- mysql - 1 个 pod 在 Minikube 上有未绑定的即时 PersistentVolumeClaims
- regex - 多个 JSON 字符串的正则表达式
- javascript - 未知方法:Internet Explorer 11 中的 selectSingleNode() || Javascipt