chiedo scusa per la domanda forse banale: esiste una funzione/formula in excel (ma per il mio obiettivo basterebbe anche word) che mi permetta, dopo aver esportato una serie di dati in excel, di ottenere un elenco o classificazione di termini piu' ricorrenti
all'interno delle celle senza la necessità di dare io stesso un input di ricerca?
Mi spiego meglio, data l'esportazione di una serie di dati all'interno delle celle che conterranno quindi delle semplici descrizioni senza una precisa schematizzazione, avrei bisogno di individuare quali sono i termini piu' ricorrenti all'interno delle descrizioni
stesse.
Ciao Valerio,
A condizione che abbia ben capito la tua richiesta, e non ne sono affatto sicuro, prova qualcosa del genere:
Alt-F11 per aprire l'editor di VBA
Alt-IM per inserire un nuovo modulo di codice
Nel nuovo modulo vuoto, incolla il seguente codice:
'==========>>
Option Explicit
'---------->>
Public Sub Tester()
'\inserisci un riferimento alla libreria: Microsoft Scripting Runtime
'\ Menu | Strumenti | Riferimenti
Dim WB As Workbook
Dim srcSH As Worksheet, destSH As Worksheet
Dim Rng As Range
Dim rCell As Range
Dim v As Variant, aVal As Variant
Dim oDic As Scripting.Dictionary
Dim arrData As Variant, arrIn() As Variant, ArrOut As Variant
Dim arrPunctuation As Variant, arrReplace As Variant, arrWith As Variant
Dim i As Long, j As Long, k As Long
Dim iLastRow As Long, iCount As Long
Dim sStr As String
Dim blAscending As Boolean
Const ColonnaDati As String = "A"
'<<===== Modifica
Set WB = Workbooks("Pippo.xlsx")
'<<===== Modifica
With WB
Set srcSH = .Sheets("Foglio1") '<<===== Modifica
Set destSH = .Sheets("Foglio2") '<<===== Modifica
End With
With srcSH
iLastRow = LastRow(srcSH, .Columns("A:A"))
Set Rng = .Range(ColonnaDati & "1:" & ColonnaDati & iLastRow)
End With
arrPunctuation = VBA.Array(".", ",", ";", ":", "!", "?", "(", ")")
arrReplace = VBA.Array("all'", "l'", "/")
arrWith = VBA.Array("al ", "il ", " ")
arrData = Rng.Value
For i = LBound(arrData) To UBound(arrData, 1)
sStr = arrData(i, 1)
For j = LBound(arrPunctuation) To UBound(arrPunctuation)
sStr = Replace(Expression:=sStr, _
Find:=arrPunctuation(j), _
Replace:="", _
Start:=1, _
Count:=-1, _
Compare:=vbTextCompare)
Next j
For j = LBound(arrReplace) To UBound(arrReplace)
sStr = Replace(Expression:=sStr, _
Find:=arrReplace(j), _
Replace:=arrWith(j), _
Start:=1, _
Count:=-1, _
Compare:=vbTextCompare)
Next j
arrData(i, 1) = sStr
Next i
Set oDic = New Scripting.Dictionary
oDic.CompareMode = TextCompare
With oDic
For j = LBound(arrData, 1) To UBound(arrData, 1)
v = Split(arrData(j, 1), Space(1))
For k = 0 To UBound(v)
aVal = v(k)
If Not .Exists(aVal) Then
.Add Item:=1, Key:=aVal
Else
.Item(aVal) = .Item(aVal) + 1
End If
Next k
Next j
iCount = .Count
ReDim arrIn(1 To iCount, 1 To 2)
For i = 1 To iCount
arrIn(i, 1) = .Keys(i - 1)
arrIn(i, 2) = .Items(i - 1)
Next i
End With
Call QuickSort(arrIn, 2, LBound(arrIn, 1), UBound(arrIn, 1), blAscending)
With destSH
.Range("A1:B1").Value = Array("Parola", "Quantità")
.Range("A2").Resize(iCount, 2).Value = arrIn
.Columns.AutoFit
End With
End Sub
'----------->>
Function LastRow(SH As Worksheet, _
Optional Rng As Range)
If Rng Is Nothing Then
Set Rng = SH.Cells
End If
On Error Resume Next
LastRow = Rng.Find(What:="*", _
After:=Rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
'----------->>
Public Sub QuickSort(SortArray, col, L, R, bAscending)
'\ TomOgilvy: http://goo.gl/ninpZW
'Originally Posted by Jim Rech 10/20/98 Excel.Programming
'Modified to sort on first column of a two dimensional array
'Modified to handle a second dimension greater than 1 (or zero)
'Modified to do Ascending or Descending
Dim i, j, X, Y, mm
i = L
j = R
X = SortArray((L + R) / 2, col)
If bAscending Then
While (i <= j)
While (SortArray(i, col) < X And i < R)
i = i + 1
Wend
While (X < SortArray(j, col) And j > L)
j = j - 1
Wend
If (i <= j) Then
For mm = LBound(SortArray, 2) To UBound(SortArray, 2)
Y = SortArray(i, mm)
SortArray(i, mm) = SortArray(j, mm)
SortArray(j, mm) = Y
Next mm
i = i + 1
j = j - 1
End If
Wend
Else
While (i <= j)
While (SortArray(i, col) > X And i < R)
i = i + 1
Wend
While (X > SortArray(j, col) And j > L)
j = j - 1
Wend
If (i <= j) Then
For mm = LBound(SortArray, 2) To UBound(SortArray, 2)
Y = SortArray(i, mm)
SortArray(i, mm) = SortArray(j, mm)
SortArray(j, mm) = Y
Next mm
i = i + 1
j = j - 1
End If
Wend
End If
If (L < j) Then Call QuickSort(SortArray, col, L, j, bAscending)
If (i < R) Then Call QuickSort(SortArray, col, i, R, bAscending)
End Sub
'<<==========
Alt-Q per chiudere l'editor di VBA e tornare a Excel.
Alt-F8 per aprire la finestrina macro
Seleziona Tester | Esegui
Prima di eseguire il codice:
Menu | Strumenti | Riferimenti | Microsoft Scripting Runtime
===
Regards,
Norman