sbContainsAllChars
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 - takes the summands as they are
False - works on the summands' percentages to make all percentages add up to 100% exactly
bDontAmend
Optional - standard value is False if not provided
True - Function treats alls String as upper case
False - Function is case sensitive

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
sbContainsAllChars.xlsm
19KB
Binary
sbContainsAllChars.xlsm
Last modified 2yr ago