“Censorship ends in logical completeness when nobody is allowed to read any books except the books that nobody reads.” [George Bernard Shaw]

Name

sbContainsAllChars - True if all characters given in sChars exist in sString as often as given in sChars, False if not.

Synopsis

sbContainsAllCHars(sString, sChars, [bIgnoreCase])

Description

sbContainsAllChars retuns True if all characters given in sChars exist in sString as often as given in sChars, False if not.

Example

See graphic above

Options

sString - String in which all characters will be searched.

sChars - Characters which need to appear in sString. Note that characters can be stated more than once, then they need to appear as often in sString as in sChars.

bIgnoreCase - Optional - standard value is False if not provided, True - upper case and lower case are treated as equals, False acts case sensitive

Appendix – sbContainsAllChars Code

Please read my Disclaimer.

Option Explicit

Function sbContainsAllChars(ByVal sString As String, _
    ByVal sChars As String, _
    Optional bIgnoreCase As Boolean = False) As Boolean
'Returns True if all characters given in sChars exist in sString
'as often as given in sChars. Returns False if not.
'Question was raised: https://www.ms-office-forum.net/forum/showthread.php?p=1969791#post1969791
'Reverse("moc.LiborPlus.www") PB V0.1 21-Feb-2020 (C) (P) by Bernd Plumhoff
Dim i As Long, j As Long, lTotal As Long
Dim lChars(0 To 255) As Long

If sChars = "" Then
    sbContainsAllChars = True
    Exit Function
End If
If sString = "" Or Len(sString) < Len(sChars) Then
    sbContainsAllChars = False
    Exit Function
End If
If bIgnoreCase Then
    sString = UCase(sString)
    sChars = UCase(sChars)
End If
For i = 1 To Len(sChars)
    j = Asc(Mid(sChars, i, 1))
    lChars(j) = lChars(j) + 1
    lTotal = lTotal + 1
Next i
sbContainsAllChars = False
For i = 1 To Len(sString)
    j = Asc(Mid(sString, i, 1))
    If lChars(j) > 0 Then
        lChars(j) = lChars(j) - 1
        lTotal = lTotal - 1
        If lTotal = 0 Then Exit For
    End If
Next i
sbContainsAllChars = lTotal = 0
End Function

Please read my Disclaimer.

sbContainsAllChars.xlsm [17 KB Excel file, open and use at your own risk]