IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

recherche sur deux critères dans la même cellule avec la méthode FIND


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Femme Profil pro
    information manager
    Inscrit en
    Janvier 2018
    Messages
    24
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : information manager

    Informations forums :
    Inscription : Janvier 2018
    Messages : 24
    Par défaut recherche sur deux critères dans la même cellule avec la méthode FIND
    Bonjour,

    Je souhaiterais dans chaque cellule de la colonne E chercher sur deux termes différents. Le code ci-dessous ne correspond qu'à un seul terme de recherche ("XXXX"). Comment ajouter un second terme de recherche c.à.d sur "XXXX" AND "YYYYY" dans la même cellule ? Expressions régulières ?


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    Sub resume()
     
    Dim i As Integer
    Dim LR As Integer
     
     
    LR = Sheets("automatisation resume").Range("C" & Rows.Count).End(xlUp).Row
     
    For i = 1 To LR
     
    If Not Range("E" & i).Find("XXXXXXX", LookAt:=xlPart, MatchCase:=True) Is Nothing Then
        Sheets("automatisation resume").Range("F" & i).Value = "AAAAA"
     
     
    End If
     
     
    Next i
     
    End Sub
    Merci d'avance,

    A.

  2. #2
    Expert confirmé Avatar de BENNASR
    Homme Profil pro
    Responsable comptable & financier
    Inscrit en
    Décembre 2013
    Messages
    2 974
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Responsable comptable & financier
    Secteur : Finance

    Informations forums :
    Inscription : Décembre 2013
    Messages : 2 974
    Par défaut
    bonsoir
    une proposition avec boucle
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    Sub cherche()
    Dim F As Worksheet
    Dim I As Long
     Application.ScreenUpdating = False
     Set F = Sheets("automatisation resume")
    I = F.Cells(Rows.Count, 5).End(xlUp).Row
    Dim C As Range
    For Each C In F.Range("E2:E" & I)
    If C.Value = "XXXX" And C.Offset(0, 1).Value = "YYYY" Then MsgBox "j'ai trouvé dans la ligne numéro :   " & C.Row
    Next C
     Application.ScreenUpdating = True
    End Sub

  3. #3
    Expert confirmé Avatar de BENNASR
    Homme Profil pro
    Responsable comptable & financier
    Inscrit en
    Décembre 2013
    Messages
    2 974
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Responsable comptable & financier
    Secteur : Finance

    Informations forums :
    Inscription : Décembre 2013
    Messages : 2 974
    Par défaut
    avec un filtre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Sub testtt()
    Dim F As Worksheet
    Dim I As Long
     Application.ScreenUpdating = False
     Set F = Sheets("automatisation resume")
    I = F.Cells(Rows.Count, 5).End(xlUp).Row
    F.Range("A1:F" & I).AutoFilter Field:=5, Criteria1:="XXXX"
    F.Range("A1:F" & I).AutoFilter Field:=6, Criteria1:="YYYY"
     Application.ScreenUpdating = True
    End Sub

  4. #4
    Expert confirmé
    Avatar de MarcelG
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2009
    Messages
    3 449
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2009
    Messages : 3 449
    Billets dans le blog
    7
    Par défaut
    Bonsoir,

    Autre piste

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    Option Explicit
     
    Public Sub cherche_double()
     
    Dim dernl As Long
    Dim c As Range
     
    With Feuil1
            dernl = .Cells(.Rows.Count, 5).End(xlUp).Row
            For Each c In .Range("E1:E" & dernl)
                    With c
                            If InStr(.Value, "pa") > 0 And InStr(.Value, "mo") > 0 Then
                                    Debug.Print .Address
                            End If
                    End With
            Next c
    End With
     
    End Sub
    Un autre processus aurait consisté à créer l'union des cellules contenant le 1er terme en utilisant la méthode Fiind.
    Ensuite, chercher le 2ème terme dans cet objet Range créé.

  5. #5
    Expert confirmé
    Avatar de MarcelG
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2009
    Messages
    3 449
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2009
    Messages : 3 449
    Billets dans le blog
    7
    Par défaut
    Vraiment pour se faire plaisir.
    Je préfère le 1er code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    Option Explicit
     
    Public Sub cherche_double_V2()
     
    Dim dernl As Long
    Dim t As Range, P As Range
    Dim ladress As String
     
    Dim c As Range
     
    With Feuil1
            dernl = .Cells(.Rows.Count, 5).End(xlUp).Row
            With .Range("E1:E" & dernl)
                    Set t = .Find(What:="pa", Lookat:=xlPart)
                    If Not t Is Nothing Then
                            ladress = t.Address
                            Do
                                    If P Is Nothing Then
                                            Set P = t
                                    Else
                                            Set P = Union(P, t)
                                    End If
                                    Set t = .FindNext(t)
                            Loop While Not t Is Nothing And t.Address <> ladress
                    End If
            End With
    End With
     
    Debug.Print P.Address
     
    If Not P Is Nothing Then
     
            With P
                    Set t = .Find(What:="mo", Lookat:=xlPart)
                    If Not t Is Nothing Then
                            ladress = t.Address
                            Do
                                    Debug.Print t.Address
                                    Set t = .FindNext(t)
                            Loop While Not t Is Nothing And t.Address <> ladress
                    End If
            End With
     
    End If
     
     
    If Not t Is Nothing Then _
            Set t = Nothing
     
    If Not P Is Nothing Then _
            Set P = Nothing
     
    End Sub


    Bonne soirée à vous. Bonne soirée au Forum.

Discussions similaires

  1. itération sur deux tableaux dans la même boucle
    Par romson2 dans le forum Struts 2
    Réponses: 0
    Dernier message: 06/06/2012, 09h06
  2. [XL-2007] Recherche sur deux critères
    Par Issah95 dans le forum Excel
    Réponses: 2
    Dernier message: 02/12/2011, 18h13
  3. [XL-2007] recherche sous 2 critères dans la même cellule
    Par Azaline dans le forum Excel
    Réponses: 7
    Dernier message: 24/08/2011, 22h48
  4. [VxiR2] doublons : deux objets dans la même cellule
    Par BipBipBO dans le forum Deski
    Réponses: 3
    Dernier message: 28/02/2011, 17h04
  5. recherche saut de ligne dans une même cellule
    Par dado91400 dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 18/03/2009, 16h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo