Nombre d’occurrence de mots sur excel

nouhaaa1995 Messages postés 79 Statut Membre -  
ccm81 Messages postés 11033 Statut Membre -
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.

2 réponses

  1. cs_Le Pivert Messages postés 8437 Statut Contributeur 730
     
    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
  2. ccm81 Messages postés 11033 Statut Membre 2 434
     
    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