
Function HowMany(Optional ByVal String1, Optional ByVal String2, Optional ByVal Compare As VbCompareMethod = vbBinaryCompare) As Integer
Dim intStart As Integer
Dim intCount As Integer
Dim intInstr As Integer
intCount = 0
intStart = 1
intInstr = InStr(intStart, String1, String2, Compare)
Do While intInstr > 0
intCount = intCount + 1
intStart = intInstr + Len(String2)
intInstr = InStr(intStart, String1, String2, Compare)
Loop
HowMany = intCount
End Function |
'restituisce solo il numero di sottostringhe in una stringa data
Len(Replace(stringa, testocercato, testocercato & "*")) - Len(stringa)
'questa versione restituisce anche la posizione delle sottostringhe nella stringa
Function conteggio(stringa As String, sottostringa As String) As String
Dim i As Long, count As Long, s As String
i = InStr(stringa, sottostringa)
Do While i
count = count + 1
s = s & i & ", "
i = InStr(i + 1, stringa, sottostringa)
Loop
If count > 0 Then
s = Left(s, Len(s) - 2)
conteggio = count & " [" & s & "]"
Else
conteggio = "[Not found]"
End If
End Function |
Function conteggio_byregex(stringa As String, sottostringa As String) As String
Dim re As Object, match As Variant, matchcoll As Variant
Dim s As String
Set re = CreateObject("VBScript.RegExp")
re.Pattern = "(" & sottostringa & ")"
re.IgnoreCase = True
re.Global = True
Set matchcoll = re.Execute(stringa)
ReDim res(1, matchcoll.count) As Variant
s = matchcoll.count
If matchcoll.count > 0 Then
s = s & " ["
For Each match In matchcoll
s = s & match.firstindex + 1 & ", "
Next
s = Left(s, Len(s) - 2) & "]"
End If
conteggio_byregex = s
End Function |
ELENCO UNIVOCO BY CANAPONE =SE(VAL.ERRORE(INDICE($A$1:$A$8;PICCOLO(SE(VAL.NUMERO(CONFRONTA(RIF.RIGA($A$1:$A$8);CONFRONTA($A$1:$A$8;$A$1:$A$8;0);0));CONFRONTA($A$1:$A$8;$A$1:$A$8;0);"");RIGHE($A$1:A1))));"";INDICE($A$1:$A$8;PICCOLO(SE(VAL.NUMERO(CONFRONTA(RIF.RIGA($A$1:$A$8);CONFRONTA($A$1:$A$8;$A$1:$A$8;0);0));CONFRONTA($A$1:$A$8;$A$1:$A$8;0);"");RIGHE($A$1:A1)))) |
