C
cutbill1234
Guest
Bonjour à tous,
j'aimerais savoir ce qui ne va pas dans la macro (merci Michel). En effet lorsque la recherche a trouvé ma valeur, lorsque je click sur le "OUI" ou "NON" du message " Voulez vous continuer la recherche ? ", je reviens sur la feuille ou se trouve mon bouton (feuile 1). J'aimerais qu'une fois la valeur trouvé elle reste sur la cellule.
Voici la macro :
Sub CommandButton2_Click()
Dim countTot As Long
Dim counter As Long
Dim strSearchString As String
Dim ws As Object
Dim foundCell As Variant
Dim loopAddr As Variant
Dim returnValue As String
strSearchString = InputBox(Prompt:="Saisir la valeur à chercher.", Title:="Recherche")
If strSearchString = "" Then Exit Sub
For Each ws In Worksheets
countTot = countTot + Application.CountIf(ws.UsedRange, "=" & strSearchString)
Next ws
If countTot = 0 Then
returnValue = MsgBox(" La valeur " & strSearchString & " n'est pas enregistrée ", vbOKOnly, " Message ")
Else
counter = 0
For Each ws In Worksheets
With ws
.Activate
Set foundCell = .Cells.Find(What:=strSearchString, LookIn:=xlValues, LookAt:=xlPart)
If Not foundCell Is Nothing Then
loopAddr = foundCell.Address
Do
counter = counter + 1
foundCell.Activate
returnValue = MsgBox(" La valeur " & strSearchString & " est enregistrée " & countTot & " fois " & vbLf & _
" Voulez vous continuer la recherche ? ", vbYesNo, "Message")
If returnValue = vbNo Then Exit For
Set foundCell = .Cells.FindNext(After:=foundCell)
Loop While Not foundCell Is Nothing And _
foundCell.Address <> loopAddr
End If
End With
Next ws
End If
Sheets(1).Select
End Sub
j'aimerais savoir ce qui ne va pas dans la macro (merci Michel). En effet lorsque la recherche a trouvé ma valeur, lorsque je click sur le "OUI" ou "NON" du message " Voulez vous continuer la recherche ? ", je reviens sur la feuille ou se trouve mon bouton (feuile 1). J'aimerais qu'une fois la valeur trouvé elle reste sur la cellule.
Voici la macro :
Sub CommandButton2_Click()
Dim countTot As Long
Dim counter As Long
Dim strSearchString As String
Dim ws As Object
Dim foundCell As Variant
Dim loopAddr As Variant
Dim returnValue As String
strSearchString = InputBox(Prompt:="Saisir la valeur à chercher.", Title:="Recherche")
If strSearchString = "" Then Exit Sub
For Each ws In Worksheets
countTot = countTot + Application.CountIf(ws.UsedRange, "=" & strSearchString)
Next ws
If countTot = 0 Then
returnValue = MsgBox(" La valeur " & strSearchString & " n'est pas enregistrée ", vbOKOnly, " Message ")
Else
counter = 0
For Each ws In Worksheets
With ws
.Activate
Set foundCell = .Cells.Find(What:=strSearchString, LookIn:=xlValues, LookAt:=xlPart)
If Not foundCell Is Nothing Then
loopAddr = foundCell.Address
Do
counter = counter + 1
foundCell.Activate
returnValue = MsgBox(" La valeur " & strSearchString & " est enregistrée " & countTot & " fois " & vbLf & _
" Voulez vous continuer la recherche ? ", vbYesNo, "Message")
If returnValue = vbNo Then Exit For
Set foundCell = .Cells.FindNext(After:=foundCell)
Loop While Not foundCell Is Nothing And _
foundCell.Address <> loopAddr
End If
End With
Next ws
End If
Sheets(1).Select
End Sub