There used to be a Windows API (Shlwapi.dll) that would do it, but I don't think it's available any more

I think that some kind of loop is needed, but you can make it as efficient as possible

I tried adding logic to remove duplicated characters from the string being tested, but that added processing time some it just seemed more efficient to keep it simple

So in the example, 'A' is checked 4 times in "AAAANNNPPP****----$$$$$#####"


Option Explicit
Function OnlyCertainChar(OnlyTheseAllowed As String, CheckThis As String) As Boolean
    Dim i As Long
    
    OnlyCertainChar = False
    
    For i = 1 To Len(CheckThis)
        If InStr(OnlyTheseAllowed, Mid(CheckThis, i, 1)) = 0 Then Exit Function
    Next I
    
    OnlyCertainChar = True
End Function


Sub test()
    MsgBox OnlyCertainChar("ANP*-$#", "ZAAAANNNPPP****----$$$$$#####")
    MsgBox OnlyCertainChar("ANP*-$#", "AAAANNNPPP****----$$$$$#####")

End Sub