Bonjour le forum :)
J'essaie d'analyser une base de données où des utilisateurs laisses des commentaires. Je me suis donc créer une macro qui permet de mettre dans un dictionnaire tous les mots (.Keys) et de les comptabiliser, le résultat étant aussi stocké dans le dictionnaire (.Items).
Jusque là tout fonctionne, mais je bute sur une optimisation du code. Je cherche , avant d'analyser un mot, à retirer tous symboles potentiels.
Je donne un exemple ci-dessous :
- Dans une cellule se trouve la phrase "Coucou, :) comment ça va ?"
- Le code va regarder chaque mot les uns après les autres (j'utilise comme séparateur le " ")
- Sur le premier interval "Coucou," il y a une ","
- je veux donc obtenir "Coucou"
Et là vous avez envie de me dire "utilise Replace !" Replace("Coucou,",",",""), et bien c'est ce que j'ai fait et ça ne marche pas
Bref je comprend pas pourquoi
Option Explicit
Sub DictionnaireV2()
Dim f As Worksheet
Dim h As Long, i As Long, j As Long, k, l, cpt As Long, Epure As Long, DernLig As Long
Dim LongExt As Integer
Dim tempo As String, Decoupe() As String
Dim Mots As Variant, Plage As Variant, Symb As Variant
Dim CentPourCent As Long, Boucle As Long
Dim Dico, SymbTBL()
MsgBox "La procédure suivante permet d'identifier les taches les plus récurrentes et mettre à jour le PARETO TOP10.", vbInformation, "Extraction"
Set f = ThisWorkbook.Worksheets(Feuil1.Name)
Set Dico = CreateObject("Scripting.Dictionary")
SymbTBL = Array(" ", ",", "?", ";", ".", "/", ":", "!", "§", "%", "*", "µ", "+", "=", "}", ")", "°", "]", "@", "_", "\", "-", "|", "[", "(", "'", "{", "&", """")
LongExt = Application.InputBox("Longueur minimum de caractère à extraire ?", "Extraction", 1, Type:=1)
If LongExt = 0 Then Exit Sub
DernLig = f.Range("A" & f.Rows.Count).End(xlUp).Row
Plage = f.Range("J2:J" & DernLig)
'With UserForm2
' .Show 0
' CentPourCent = .Label1.Width - 3
For i = LBound(Plage) To UBound(Plage)
' DoEvents
' UserForm2.Label2.Width = i * CentPourCent / UBound(Plage)
' .Caption = "Extraction des termes : " & Format((i * CentPourCent / UBound(Plage)) / CentPourCent, "##0.00%")
If f.Range("Q" & i + 1) = "NON" Then
Decoupe = Split(Plage(i, 1), " ")
For j = LBound(Decoupe) To UBound(Decoupe)
For Each Symb In SymbTBL
tempo = Replace(Decoupe(j), Symb, "")
Next Symb
If tempo <> "" And Len(tempo) > LongExt Then Dico(UCase(tempo)) = ""
Next j
End If
Next i
For Each Mots In Dico.keys
cpt = 0
For k = LBound(Plage) To UBound(Plage)
Decoupe = Split(Plage(k, 1), " ")
For l = LBound(Decoupe) To UBound(Decoupe)
For Each Symb In SymbTBL
tempo = UCase(Replace(Decoupe(l), Symb, ""))
Next Symb
If tempo = Mots Then cpt = cpt + 1
Next l
Next k
Dico.Item(Mots) = cpt
Debug.Print Mots & " - " & Dico.Item(Mots)
Next Mots
'End With
End Sub
Par avance, merci de l'interet porté au sujet !