首页 > 解决方案 > 比较不是真的;但发送到 MsgBox 的值显示它应该是

问题描述

这是我的代码的一部分..

'Loop through each SOP audit file
    For Each oFile In oFiles
        'MsgBox (RemoveLeadingZeroes(Split(oFile.Name, "-")(2)))
        'Loop through all SOP IDs stored in COL A
        For Each cel In SOPID
            MsgBox (RemoveLeadingZeroes(Split(oFile.Name, "-")(2)) & " : " & cel)
            'See if SOP ID in COL A matches SOP ID in Audit file name
            If RemoveLeadingZeroes(Split(oFile.Name, "-")(2)) = cel Then
                MsgBox ("Match found on SOP ID: " & cel)
            End If
        Next cel
    Next oFile

这是使用该行比较的值的屏幕截图...

MsgBox (RemoveLeadingZeroes(Split(oFile.Name, "-")(2)) & " : " & cel)

为什么如果两个值确实匹配,则触发 MsgBox 的 If() 语句不表示存在匹配?是否将一个视为字符串,将另一个值视为范围?那会影响它吗?

在此处输入图像描述

标签: excelvba

解决方案


使用 Trim() 删除空格。


推荐阅读