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 :

macro à compléter


Sujet :

Macros et VBA Excel

  1. #1
    Membre habitué
    Homme Profil pro
    Moi, je ne fais que passer, excusez le dérangement
    Inscrit en
    Mars 2013
    Messages
    653
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Vienne (Limousin)

    Informations professionnelles :
    Activité : Moi, je ne fais que passer, excusez le dérangement

    Informations forums :
    Inscription : Mars 2013
    Messages : 653
    Points : 146
    Points
    146
    Par défaut macro à compléter
    Bonjour le forum,

    J'ai 5 feuilles et lorsque la recherche se fait tout fonctionne mais lorsque ça arrive sur la feuille LOGICIELS - LICENCES la couleur continue sur la colonne E.
    J'ai loupé quelque chose mais quoi?
    Quelqu'un peut-il voir où se trouve la "bêtise" car elle elle doit-être ENORME?
    Merci d'avance

    Voici la macro:

    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
    Sub RechercherNoms()
    Dim Sh As Worksheet
    Dim c As Range
    Dim Nom As String, firstAddress As String
     
    Nom = InputBox("Nom à chercher dans toutes les feuilles", "Rechercher")
    If Nom <> "" Then
        For Each Sh In ThisWorkbook.Worksheets
          'Sh.Range("A3:E" & Sh.Range("A" & Rows.Count).End(xlUp).Row).Interior.ColorIndex = xlNone
            Set c = Sh.Columns("A:E").Find(Nom, LookIn:=xlValues, LookAt:=xlPart)
            If Not c Is Nothing Then
                Sh.Activate
                c.Select
                firstAddress = c.Address
                Do
                  If Sh.Name = "TOTO" Then
                    Range("A" & c.Row & ":C" & c.Row).Interior.ColorIndex = 38
                  Else
                   If Sh.Name = "LOGICIELS - LICENCES" Then
                    Range("A" & c.Row & ":D" & c.Row).Interior.ColorIndex = 38
                  Else
                  End If
                    Range("A" & c.Row & ":E" & c.Row).Interior.ColorIndex = 38
                  End If
                  strreponse = MsgBox(Sh.Name & "!" & c.Address & vbCrLf & _
                     "Oui pour continuer la recherche" & vbLf & _
                     "Non pour sortir", vbYesNo)
                     If strreponse = vbNo Then Exit Sub
                    Set c = Sh.Columns("A:E").FindNext(c)
                    c.Select
                Loop While Not c Is Nothing And c.Address <> firstAddress
                Set c = Nothing
          End If
        Next Sh
    End If
    End Sub

  2. #2
    Membre confirmé Avatar de graphikris
    Homme Profil pro
    Pas tres doué
    Inscrit en
    Décembre 2012
    Messages
    1 215
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Pas tres doué
    Secteur : Conseil

    Informations forums :
    Inscription : Décembre 2012
    Messages : 1 215
    Points : 523
    Points
    523
    Par défaut
    Bonjour,

    Avant de déclencher ta macro, ouvre VBA (Alt + F11), tu réduit pour voir ton classeur Excel puis tu presses la touche F8. A chaque pression sur F8, ta macro se déroule pas a pas. Lorsque tu arrives sur ton erreur (colonne E coloriée), tu stoppes puis tu modifies ta macro.

  3. #3
    Membre habitué
    Homme Profil pro
    Moi, je ne fais que passer, excusez le dérangement
    Inscrit en
    Mars 2013
    Messages
    653
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Vienne (Limousin)

    Informations professionnelles :
    Activité : Moi, je ne fais que passer, excusez le dérangement

    Informations forums :
    Inscription : Mars 2013
    Messages : 653
    Points : 146
    Points
    146
    Par défaut
    Bonjour graphikris,
    Fait et ça n'accroche pas.
    Je pense que c'est ENORME mais voit pas pour l'instant.
    Merci à toi

  4. #4
    Membre confirmé Avatar de graphikris
    Homme Profil pro
    Pas tres doué
    Inscrit en
    Décembre 2012
    Messages
    1 215
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Pas tres doué
    Secteur : Conseil

    Informations forums :
    Inscription : Décembre 2012
    Messages : 1 215
    Points : 523
    Points
    523
    Par défaut
    met ton fichier en lien

  5. #5
    Inactif  

    Homme Profil pro
    cuisiniste
    Inscrit en
    Avril 2009
    Messages
    15 374
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : cuisiniste
    Secteur : Bâtiment

    Informations forums :
    Inscription : Avril 2009
    Messages : 15 374
    Points : 12 068
    Points
    12 068
    Billets dans le blog
    8
    Par défaut heu
    onjour
    pour moi il y a un end if en trop
    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
    Sub RechercherNoms()
    Dim Sh As Worksheet
    Dim c As Range
    Dim Nom As String, firstAddress As String
     
    Nom = InputBox("Nom à chercher dans toutes les feuilles", "Rechercher")
    If Nom <> "" Then
        For Each Sh In ThisWorkbook.Worksheets
          'Sh.Range("A3:E" & Sh.Range("A" & Rows.Count).End(xlUp).Row).Interior.ColorIndex = xlNone
            Set c = Sh.Columns("A:E").Find(Nom, LookIn:=xlValues, LookAt:=xlPart)
            If Not c Is Nothing Then
                Sh.Activate
                c.Select
                firstAddress = c.Address
                Do
                  If Sh.Name = "TOTO" Then
                    Range("A" & c.Row & ":C" & c.Row).Interior.ColorIndex = 38
                  Else
                   If Sh.Name = "LOGICIELS - LICENCES" Then
                    Range("A" & c.Row & ":D" & c.Row).Interior.ColorIndex = 38
                  Else
                  End If
                    Range("A" & c.Row & ":E" & c.Row).Interior.ColorIndex = 38
                  End If
                  strreponse = MsgBox(Sh.Name & "!" & c.Address & vbCrLf & _
                     "Oui pour continuer la recherche" & vbLf & _
                     "Non pour sortir", vbYesNo)
                     If strreponse = vbNo Then Exit Sub
                    Set c = Sh.Columns("A:E").FindNext(c)
                    c.Select
                Loop While Not c Is Nothing And c.Address <> firstAddress
                Set c = Nothing
          End If
        Next Sh
    End If
    End Sub
    mais tu aurais fait pluspropre avec un select case

  6. #6
    Expert éminent

    Homme Profil pro
    Curieux
    Inscrit en
    Juillet 2012
    Messages
    5 139
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Curieux
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Juillet 2012
    Messages : 5 139
    Points : 9 974
    Points
    9 974
    Billets dans le blog
    5
    Par défaut
    Bonjour,

    je ne comprend pas très bien ce que tu veux faire :

    - feuille TOTO = colorier en colonne A à C
    - autres feuilles : colorier en colonne A à E

    il y a des feuilles dans le classeur qui ne doivent pas être traitées ??
    par ailleurs, tu as mis en commentaire la ligne de code qui efface les couleurs avant de faire le traitement, c'est normal ?

    voici un exemple à adapter ... ou alors il faut mieux préciser les choses pour qu'on puisse t'aider

    - suppression des couleurs dans chaque feuille
    - Recherche du mot
    - Pour chaque ligne où figure le résultat : colorier la colonne A à E SAUF la feuille TOTO (colorier colonne A à C)

    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
    Sub RechercherNoms()
    Dim Sh As Worksheet
    Dim c As Range
    Dim Nom As String, firstAddress As String
     
    Nom = InputBox("Nom à chercher dans toutes les feuilles", "Rechercher")
     
    If Nom <> "" Then
     
        For Each Sh In ThisWorkbook.Worksheets
            With Sh
                .Range("A3:E" & .Range("A" & .Rows.Count).End(xlUp).Row).Interior.ColorIndex = xlNone
     
                Set c = .Columns("A:E").Find(Nom, LookIn:=xlValues, LookAt:=xlPart)
     
                If Not c Is Nothing Then
     
                    firstAddress = c.Address
     
                    Do
                        If .Name = "TOTO" Then
                            .Range("A" & c.Row & ":C" & c.Row).Interior.ColorIndex = 38
                        Else
                            .Range("A" & c.Row & ":E" & c.Row).Interior.ColorIndex = 38
                        End If
     
                        strreponse = MsgBox(.Name & "!" & c.Address & vbCrLf & _
                                            "Oui pour continuer la recherche" & vbLf & _
                                            "Non pour sortir", vbYesNo)
     
                        If strreponse = vbNo Then Exit Sub
     
                        Set c = .Columns("A:E").FindNext(c)
     
                    Loop While Not c Is Nothing And c.Address <> firstAddress
     
                    Set c = Nothing
                End If
            End With
        Next Sh
    End If
     
    End Sub

  7. #7
    Inactif  

    Homme Profil pro
    cuisiniste
    Inscrit en
    Avril 2009
    Messages
    15 374
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : cuisiniste
    Secteur : Bâtiment

    Informations forums :
    Inscription : Avril 2009
    Messages : 15 374
    Points : 12 068
    Points
    12 068
    Billets dans le blog
    8
    Par défaut RE
    UN EXEMPLE SELON TON PRINCIPE
    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
    Sub RechercherNoms()
        Dim Sh As Worksheet, c As Range, Nom As String, firstAddress As String, col1, col2
        Nom = InputBox("Nom à chercher dans toutes les feuilles", "Rechercher")
        If Nom <> "" Then
            For Each Sh In ThisWorkbook.Worksheets
                Select Case Sh.Name
                Case "TOTO"
                    col2 = 3
                Case "LOGICIELS - LICENCES"
                    col2 = 4
                    'je supose que le END IF En trop etait pour le cas ou le nom du sheets etait diférent des deux premiers précédement cité!!!!?
                    'donc on rajoute un CASE ELSE
                Case Else
                    col2 = 5
                End Select
                With Sh
                    .Activate    ' je te met activate ici pour que tu puisse voir le travail se faire mais c'est pas utilse
                    Set c = .Range(.Cells(1, 1), .Cells(Rows.Count, col2)).Find(Nom, LookIn:=xlValues, LookAt:=xlPart)
                    If Not c Is Nothing Then
                        firstAddress = c.Address
                        Do
                            .Range(.Cells(c.Row, 1), .Cells(c.Row, col2)).Interior.ColorIndex = 38
                            c.Select ' je te met le select ici pour que tu puisse voir le sheets se colorer au fur et a mesure mais c'est pas utile car les select et activate ralentissent la macro
                            strreponse = MsgBox(Sh.Name & "!" & c.Address & vbCrLf & _
                                                "Oui pour continuer la recherche" & vbLf & _
                                                "Non pour sortir", vbYesNo)
                            If strreponse = vbNo Then Exit Sub
                            Set c = .Range(.Cells(1, 1), .Cells(Rows.Count, col2)).FindNext(c)
                        Loop While Not c Is Nothing And c.Address <> firstAddress
                        Set c = Nothing
                    End If
                End With
            Next Sh
        End If
    End Sub

  8. #8
    Membre habitué
    Homme Profil pro
    Moi, je ne fais que passer, excusez le dérangement
    Inscrit en
    Mars 2013
    Messages
    653
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Vienne (Limousin)

    Informations professionnelles :
    Activité : Moi, je ne fais que passer, excusez le dérangement

    Informations forums :
    Inscription : Mars 2013
    Messages : 653
    Points : 146
    Points
    146
    Par défaut
    Bonsoir le forum,
    Excuez moi si je n'ai pu fournir le fichier mais il est très personnel.
    Effectivement ça aurait été mieux il était même indispensable pour comprendre.
    J'ai tout revu et ça fonctionne et c'est plus facile si on veut ajouter des feuilles.

    Nouveaux codes car il y en a deux maintenant.

    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
    Sub RechercherNoms()
    Dim Sh As Worksheet
    Dim c As Range
    Dim Nom As String, firstAddress As String
     
    Nom = InputBox("Nom à chercher dans toutes les feuilles", "Rechercher")
    If Nom <> "" Then
        For Each Sh In ThisWorkbook.Worksheets
          'Sh.Range("A3:E" & Sh.Range("A" & Rows.Count).End(xlUp).Row).Interior.ColorIndex = xlNone
            Set c = Sh.Columns("A:E").Find(Nom, LookIn:=xlValues, LookAt:=xlPart)
            If Not c Is Nothing Then
                Sh.Activate
                c.Select
                firstAddress = c.Address
                Do
                  Select Case Sh.Name
                    Case "TOTO"
                      Range("A" & c.Row & ":C" & c.Row).Interior.ColorIndex = 38
                    Case "LOGICIELS - LICENCES"
                      Range("A" & c.Row & ":D" & c.Row).Interior.ColorIndex = 38
                    Case Else
                      Range("A" & c.Row & ":E" & c.Row).Interior.ColorIndex = 38
                  End Select
     
                  strreponse = MsgBox(Sh.Name & "!" & c.Address & vbCrLf & _
                     "Oui pour continuer la recherche" & vbLf & _
                     "Non pour sortir", vbYesNo)
                     If strreponse = vbNo Then Exit Sub
                    Set c = Sh.Columns("A:E").FindNext(c)
                    c.Select
                Loop While Not c Is Nothing And c.Address <> firstAddress
                Set c = Nothing
          End If
        Next Sh
    End If
    End Sub
    Autre 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
    Sub ReInitCouleurs()
    Dim Ligne As Long, Sh As Worksheet, Colonne As Integer
    Dim LaCouleur
    Dim NbColonne As Integer
     
      LaCouleur = Array(36, 35, 40, 36, 35)
      For Each Sh In Sheets
        Ligne = Sh.Range("A" & Rows.Count).End(xlUp).Row
        If Sh.Name = "TOTO" Then
          NbColonne = 3
        ElseIf Sh.Name = "LOGICIELS - LICENCES" Then
        'If Sh.Name = "LOGICIELS - LICENCES" Then
          NbColonne = 4
        Else
          NbColonne = 5
        End If
        For Colonne = 1 To NbColonne
          Sh.Range(Sh.Cells(3, Colonne), Sh.Cells(Ligne, Colonne)).Interior.ColorIndex = LaCouleur(Colonne - 1)
        Next Colonne
      Next Sh
    End Sub

  9. #9
    Membre habitué
    Homme Profil pro
    Moi, je ne fais que passer, excusez le dérangement
    Inscrit en
    Mars 2013
    Messages
    653
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Vienne (Limousin)

    Informations professionnelles :
    Activité : Moi, je ne fais que passer, excusez le dérangement

    Informations forums :
    Inscription : Mars 2013
    Messages : 653
    Points : 146
    Points
    146
    Par défaut
    Bonjour le forum,
    J'ai oublié hier au soir de remercier ceux qui ont bien voulu apporter leur pierre à la réalisation de nouveaux codes.
    Avec toutes mes excuses
    Merci patricktoulon, Merci joe.levrai et merci graphikris
    Bonne journée à vous.
    Bien cordialement

Discussions similaires

  1. [XL-2010] Compléter macro d'importation de contenu
    Par zephoenix dans le forum Excel
    Réponses: 3
    Dernier message: 23/09/2014, 09h05
  2. Création d'une macro pour compléter un tableau
    Par bingo65 dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 12/08/2014, 14h22
  3. [XL-2007] Aide pour compléter le code de la macro
    Par matthieu2701 dans le forum Macros et VBA Excel
    Réponses: 0
    Dernier message: 28/07/2013, 10h19
  4. [AC-2003] compléter automatiquement un controle avec une macro
    Par patrickCG40 dans le forum IHM
    Réponses: 1
    Dernier message: 02/12/2009, 13h55
  5. Aide pour complèter une macro VBA
    Par NEC14 dans le forum Macros et VBA Excel
    Réponses: 18
    Dernier message: 24/11/2008, 13h07

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