Bonjour,
Etant débutant je n'arrive pas à choisir une partie d'un texte ou d'un nombre dans une cellule
Par exemple je recherche atl dans une cellule ou il y a dedans atl1234,et le message retourné est "la valeur atl n'est pas enregistrée"
Merçi d'aider un débutant
Option Explicit
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:=xlWhole)
If Not foundCell Is Nothing Then
loopAddr = foundCell.Address
Do
counter = counter + 1
foundCell.Activate
If countTot = 1 Then
returnValue = MsgBox(" La valeur " & strSearchString & " est enregistrée 1 seule fois ", vbOKOnly, " Message ")
Exit Sub
End If
If counter = countTot Then
returnValue = MsgBox(" La valeur " & strSearchString & " sélectionnée est la dernière !", vbOKOnly, "Message")
Sheets("Feuil1").Activate
Range("A1").Select
Exit Sub
Else
returnValue = MsgBox(" La valeur " & strSearchString & " sélectionnée est la " & counter & " sur " & countTot & " existantes. " & vbLf & _
" Voulez vous continuer la recherche ? ", vbYesNo, "Message")
If returnValue = vbNo Then Exit For
Set foundCell = .Cells.FindNext(After:=foundCell)
End If
Loop While Not foundCell Is Nothing And foundCell.Address <> loopAddr
End If
End With
Next Ws
End If
End Sub
Etant débutant je n'arrive pas à choisir une partie d'un texte ou d'un nombre dans une cellule
Par exemple je recherche atl dans une cellule ou il y a dedans atl1234,et le message retourné est "la valeur atl n'est pas enregistrée"
Merçi d'aider un débutant
Option Explicit
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:=xlWhole)
If Not foundCell Is Nothing Then
loopAddr = foundCell.Address
Do
counter = counter + 1
foundCell.Activate
If countTot = 1 Then
returnValue = MsgBox(" La valeur " & strSearchString & " est enregistrée 1 seule fois ", vbOKOnly, " Message ")
Exit Sub
End If
If counter = countTot Then
returnValue = MsgBox(" La valeur " & strSearchString & " sélectionnée est la dernière !", vbOKOnly, "Message")
Sheets("Feuil1").Activate
Range("A1").Select
Exit Sub
Else
returnValue = MsgBox(" La valeur " & strSearchString & " sélectionnée est la " & counter & " sur " & countTot & " existantes. " & vbLf & _
" Voulez vous continuer la recherche ? ", vbYesNo, "Message")
If returnValue = vbNo Then Exit For
Set foundCell = .Cells.FindNext(After:=foundCell)
End If
Loop While Not foundCell Is Nothing And foundCell.Address <> loopAddr
End If
End With
Next Ws
End If
End Sub