Recherche dans la colonne et écrire en peu plus loin une valeur

Bonjour l'équipe;

j'aurais besoin de votre aide svp
je m'explique :

je souhaite faire une macro pour mon fichier Excel dans la feuille 1 je veux faire une recherche spécial dans la colonne "M1:M8000" je peux avoir dans les colonnes plusieurs texte par exemple :

1 - T001-T002

2 - T001-T002,Z003-Z005,T006,Z007,T201-T203,C101-C116,C117

3 - Z201-Z202,C117-C199

4 - C100-C999

5 - Z200-Z205,T001
... etc

voici le code que j'ai commencé mais je n'arrive pas a le terminer
 Private Sub CommandButton1_Click()
 Dim F As Worksheet
  Dim Z As Integer
   Set F = Feuil1
   Dim plage As Range, C As Range
   Set F = Feuil1
   Z = 100
   Set plage = F.Range("M8:M8000")
   For Each C In plage
   If C.Value = "T201"  Then F.Cells(C.Row, "AN") = Z
   Next C
End Sub

le code marche bien, mais pas pour tous les hypothèses que pour "T201"

Après je pense si vous arrivez a m'aider a ecrire le code de recherche partielle par exemple des que il trouve après la première lettre "Z où C où T" le chiffre "20" et dans les autres pareil que du "20" il écrit la valeur de Z dans la colonne "AN".
et sinon dans les autres il trouve "00" ou "10" il écrit "Tous".
et quand aussi la valeur et vide il écris "Tous"
et quand c'est ("N/A") il saute voilà.

merci d'avance pour votre aide
et j'espère que j'étais clair.

cordialement,

Bonjour

Un fichier est TOUJOURS le bienvenu

Quelle version d'excel ?

pour mac ou windows?

Quand tu as C117-C199 c'est C117 et C199 ou C117,C118... jusque C199

A+ François

Bonjour

J'utiliserai bien des expressions régulières

Au lieu de :

If C.Value = "T201" Then F.Cells(C.Row, "AN") = Z

j'écrirai (non testé, regardez google : VBA Expressions régulières)

Dim oRegEx as New RegExp
Dim oRegMatches as MatchCollection
Dim oRegMatch as Match
oRegEx.Pattern = "[ZCT]\d0"
oRegEx.Global=True
oRegEx.IgnoreCase = True
Set oRegMatches = oRegEx.Execute(C.Value)
for Each oRegMatch in oRegMatches
if Not oRegMatch is Nothing Then
if mid(oRegMatch.Value,1,2)= "2" Then F.Cells(C.Row, "AN") = Z
if mid(oRegMatch.Value,1,2)= "0" or mid(oRegMatch.Value,1,2)= "1" Then  F.Cells(C.Row, "AN")= "Tous"
End if 
Next

Bonjour Scarper,

Merci pour ta réponse et ton aide.

J'ai essayé ça, mais la macro exécute sans rien faire je trouve rien dans la Colonne "AF".

et je suis parti regarder sur internet mais j'ai pas compris.

Si tu peux m'aider.

Dim F As Worksheet
Dim oRegEx As New RegExp
Dim oRegMatches As MatchCollection
Dim oRegMatch As Match
Dim Z As Integer, C As Range, X As Integer
oRegEx.Pattern = "[ZCT]\d0"
oRegEx.Global = True
oRegEx.IgnoreCase = True
Z = "1000"
X = "500"
Set F = Feuil1
Set plage = F.Range("M8:M8000")
For Each C In plage
Set oRegMatches = oRegEx.Execute(C.Value)
For Each oRegMatch In oRegMatches
If Not oRegMatch Is Nothing Then
If Mid(oRegMatch.Value, 1, 3) = "2" Then F.Cells(C.Row, "AN") = Z
If Mid(oRegMatch.Value, 1, 3) = "0" Or Mid(oRegMatch.Value, 1, 3) = "1" Then F.Cells(C.Row, "AN") = X
If Mid(oRegMatch.Value, 1, 1) = " " Then F.Cells(C.Row, "AN") = "ALL"
End If
Next
Next
End Sub
Rechercher des sujets similaires à "recherche colonne ecrire peu loin valeur"