Nombre d’occurrence de mots sur excel

Fermé
nouhaaa1995 Messages postés 72 Date d'inscription vendredi 13 avril 2018 Statut Membre Dernière intervention 4 octobre 2018 - 16 mai 2018 à 12:52
ccm81 Messages postés 10851 Date d'inscription lundi 18 octobre 2010 Statut Membre Dernière intervention 16 avril 2024 - 16 mai 2018 à 15:35
Bonjour,
je souhaite créer un macro dans lequel je peux compter le nombre de fois qu'un mot est présent dans un classeur, le mot est une donnée d'entrée d'un combobox

merci de votre aide.
A voir également:

2 réponses

cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 728
Modifié le 16 mai 2018 à 15:01
Bonjour,

Comme ceci a adapter:

Sub WorkbookFind()
'Stéphane Royer, mpfe
Dim counter As Integer
Dim What As String
Dim sht As Worksheet
Dim found, FirstAddress
counter = 0
  What = "ECO"
  If What = "" Then Exit Sub
  For Each sht In Worksheets
    sht.Activate
    Set found = sht.Cells.Find(What)
    If Not found Is Nothing Then
      FirstAddress = found.Address
      Do
       counter = counter + 1
        found.Activate
       ' Response = MsgBox("Continuer ?", vbYesNo + vbQuestion)
       ' If Response = vbNo Then Exit Sub
        Set found = Cells.FindNext(After:=ActiveCell)
        If found.Address = FirstAddress Then Exit Do
        Loop
    End If
  Next sht
  MsgBox "Recherche terminée !"
  MsgBox counter
End Sub


0
ccm81 Messages postés 10851 Date d'inscription lundi 18 octobre 2010 Statut Membre Dernière intervention 16 avril 2024 2 404
Modifié le 16 mai 2018 à 15:36
Bonjour à tous les deux

Peut être un peu plus simple

Sub CompterMots()
Dim nbmots As Long, F As Worksheet, mot As String
mot = "ECO"
nbmots = 0
For Each F In Worksheets
  nbmots = nbmots + Application.WorksheetFunction.CountIf(F.Cells, mot)
Next F
MsgBox "Recherche terminée, " & nbmots & " occurences du mot " & mot
End Sub


Cdlmnt
0