Moderatori: Anthony47, Flash30005
Sub test_Combina_RE()
'di Roberto Mensa - Nick r
Dim rng As Excel.Range
For i = 4 To 11
lettere = lettere & Cells(1, i)
Next
num = Range("C1").Value
Stop
Set rng = Nuovo_Range(ThisWorkbook, "Combina_RE_Res ")
'Combina_RE "TOILACOT", 5, rng
Combina_RE lettere, num, rng
End Sub
Function Nuovo_Range( _
Wb As Excel.Workbook, _
Optional Nome_base As _
String = "Foglio") As Excel.Range
'di Roberto Mensa - Nick r
'restituisce la cella A1 di un nuovo foglio
'il nuovo foglio viene rinominato in base
'all'argomento Nome_base
Dim b
Set Nuovo_Range = Wb.Worksheets.Add.Range("A1")
Application.ScreenUpdating = False
On Error Resume Next
Do
Err.Clear
Nuovo_Range.Parent.Name = Nome_base & b
b = b + 1
Loop While Err
Application.ScreenUpdating = True
End Function
Sub Combina_RE( _
ByVal sC As String, _
ByVal lS As Long, _
StartRng As Excel.Range)
'di Roberto Mensa - Nick r
'https://sites.google.com/site/e90e50/vbscript/regexp/anagrammi-e-combinazioni
Dim RE As Object
Dim L1 As Long, L2 As Long
Dim S1 As String, S2 As String, S3 As String
Dim V1 As Variant, B1 As Boolean
'Combinazioni con ripetizione
'sC è l'insieme dei caratteri
'lS è la lunghezza delle stringhe
'risultati
'StartRng è la cella da cui partire
'per scrivere le combinazioni di
'ogni carattere di sC (anche ripetuto)
'per una lunghezza di lS caratteri
'volendo ottenere tutte le combinazioni
'con lunghezza da 1 a lS basta escludere
'la if interruttore all'interno del loop
Set RE = CreateObject("VBScript.RegExp")
L1 = Len(sC)
RE.Global = True
'creo la stringa di partenza
'con i singoli caratteri delimitati
'da uno spazio
RE.Pattern = "\w"
S1 = RE.Replace(sC, " $&")
'creo la stringa di controllo di
'fine loop composta da lS caratteri
'tutti uguali all'ultimo carattere
'di sC
S2 = String(lS, Right(sC, 1))
'ciclo aggiungendo ad ogni parola
'(serie di caratteri delimitati da
'spazio) ogni carattere di sC
'al primo for azzero la stringa
'liberando memoria (utilizzo una
'variabile boolean come interruttore)
RE.Pattern = "\w+"
Do Until S3 = S2
B1 = True
For Each V1 In RE.Execute(S1)
'l'interruttore
If B1 Then
S1 = ""
B1 = False
End If
'ciclo di polamento
For L2 = 1 To L1
S3 = V1 & Mid(sC, L2, 1)
S1 = S1 & " " & S3
Next
Next
Loop
'ultimo ciclo per caricare le
'*parole* nelle celle
L2 = 0
For Each V1 In RE.Execute(S1)
StartRng.Offset(L2) = V1
L2 = L2 + 1
Next
End Sub
Sub wYN()
Dim wArr, Lett, I As Long, J As Long, lB0 As Long, myPos
Dim wLen As Long, cW As String, myLetts As String, K As String
'
wArr = Range(Range("A1"), Range("A1").End(xlDown)).Value
Lett = Range(Range("D1"), Range("D1").End(xlToRight)).Value
'
wLen = Range("C1").Value
Range(Range("N1"), Range("N1").End(xlDown)).ClearContents '***
lB0 = LBound(wArr)
For I = lB0 To UBound(wArr)
If wArr(I, 1) = "alcol" Then Stop
If Len(wArr(I, 1)) = wLen Then
K = 0
myLetts = Join(Application.WorksheetFunction.Index(Lett, 1, 0), "_")
cW = wArr(I, 1)
For J = 1 To wLen
myPos = InStr(1, myLetts, Mid(cW, J, 1), vbTextCompare)
If myPos = 0 Then
Exit For
Else
myLetts = Replace(myLetts, Mid(cW, J, 1), "", , 1, vbTextCompare)
K = K + 1
End If
Next J
If K = wLen Then
Cells(Rows.Count, "N").End(xlUp).Offset(1, 0) = cW
End If
End If
DoEvents
Next I
MsgBox ("Completato...")
End Sub
Range(Range("N1"), Range("N" & Rows.Count).End(xlUp)).ClearContents '***
Range("N:N").ClearContents '***
.ho provato la macro di Anthony, purtroppo con office 2003 non funziona, e non riesco ha capire il perchè...
qualcuno la puo provare con office 2003... grazie
Torna a Applicazioni Office Windows
Inserire add.in nella barra di avvio veloce in excel 2003 Autore: Ricky0185 |
Forum: Applicazioni Office Windows Risposte: 4 |
Excel: problema con date se devo unirle a testi Autore: valle1975 |
Forum: Applicazioni Office Windows Risposte: 5 |
confrontare e evidenziare 2 fogli excel Autore: niccia |
Forum: Applicazioni Office Windows Risposte: 7 |
Visitano il forum: Nessuno e 4 ospiti