代码之家  ›  专栏  ›  技术社区  ›  D T

如何在字符串VBA中检查“\”?

  •  1
  • D T  · 技术社区  · 6 年前

    这是我的代码,但不起作用: enter image description here

    strText = oSheet.Cells(1, 1).Text
    If InStr(strText, "\") > 0 Then
        bPrice = True       
    End If
    

    如何在字符串中检查“\”?

    1 回复  |  直到 6 年前
        1
  •  5
  •   user4039065user4039065    6 年前

    这个 日元 是12月165号的ascii,试试,

    strText = oSheet.Cells(1, 1).Text
    If cbool(InStr(1, strText, ChrW(165))) Then
        bPrice = True       
    End If
    

    这里有一个测试,以确保您得到正确的ascii dec代码。将单元格格式化为您喜欢的格式,选择它并运行此短Sub。

    sub find165()
        dim str as string, i as long
        str = activecell.text
        for i = 1 to len(str)
            debug.print ascw(mid(str, i, 1))
        next i
    end sub
    

    查看vbe的即时窗口,查看单元格中显示的每个字符的ascii dec代码。