1

Why Like function does not work? In this case it returns:

"No, it's not"

Sub test()
    If "*ыписка по договору ук-004#1500333*" Like "выписка по договору ук-004#1500333 стд.xlsx" Then
        MsgBox "Yes, it is!"
    Else
        MsgBox "No, it's not"
    End If    
End Sub
Magnetron
  • 7,495
  • 1
  • 25
  • 41

2 Answers2

8

You have the strings backwards.

If {string} Like {substring w/wildcards} Then

Sub test()
    If "выписка по договору ук-004#1500333 стд.xlsx" Like "*ыписка по договору ук-004#1500333*" Then
        MsgBox "Yes, it is!"
    Else
        MsgBox "No, it's not"
    End If
End Sub
octano
  • 851
  • 1
  • 10
  • 18
Scott Craner
  • 148,073
  • 10
  • 49
  • 81
  • 3
    another thing is the # character is a wildcard for a number. so you would need to encapsulated it using [#] so it would look like If "выписка по договору ук-004#1500333 стд.xlsx" Like "*ыписка по договору ук-004[#]1500333*" Then – KySoto Oct 26 '18 at 16:17
2

You can also use InStr instead if your goal is to verify the existence of a string in another:

Sub test()   
    If  InStr("выписка по договору ук-004#1500333 стд.xlsx", _
        "ыписка по договору ук-004#1500333") > 0 Then
        MsgBox "Yes, it is!"
    Else
        MsgBox "No, it's not"
    End If    
End Sub
octano
  • 851
  • 1
  • 10
  • 18