Ignorer les cellules avec #NA

Salut, j'ai une macro qui s'occupe de traiter des cellules. Si le contenu de la cellule est #N/A , la macro renvoi un message "incompatibilite de type". Pourrait-on modifier la macro pour qu'elle ignore les cellules avec #N/A.

J'essaierai de vous envoyer l'application si necessaire.

For i = 2 To fin

                    If .Cells(i, 4) = "R" Then
                             x = Split(.Cells(i, 9), "(")
                            m = Split(x(1), ")")
                            n = m(0)
                            Set Cel = Feuil8.Range("A:A").Find(n, , , xlWhole)
                            If Not Cel Is Nothing Then Lig = Cel.Row
                            .Cells(i, 4) = Right(Feuil8.Cells(Lig, 2), 2)
                            .Cells(i, 4).Font.ColorIndex = 5  'met la couleur dans la cellule R
                    End If

Bonjour

essayes (pas testé)

    For i = 2 To fin
                  If Not IsError(.Cells(i,4)) Then
                        If .Cells(i, 4) = "R" Then
                                 x = Split(.Cells(i, 9), "(")
                                m = Split(x(1), ")")
                                n = m(0)
                                Set Cel = Feuil8.Range("A:A").Find(n, , , xlWhole)
                                If Not Cel Is Nothing Then Lig = Cel.Row
                                .Cells(i, 4) = Right(Feuil8.Cells(Lig, 2), 2)
                                .Cells(i, 4).Font.ColorIndex = 5  'met la couleur dans la cellule R
                       End If
                    End If

Ca focntionne, j'ai ajouter une parenthese qui manquait.

Il faudrait ajouter la meme chose a cette derniere macro:

Sub Variable_type2() 'traitement de variables, pour cellules avec "L" suivit de  "H"  Papou
    Dim i&, fin&, a&, x As Variant, n$, m, Cel As Range, Lig&
    With Feuil6
        fin = .Range("A" & Rows.Count).End(xlUp).Row
        For i = 2 To fin
            For a = 4 To 5
                If .Cells(i, a) = "L" Then  'on suppose que "H" est present dans la cellule de droite
                    If .Cells(i, 9) Like "*" & "(" & "*" Then 'si on a une parenthese
                        x = Split(.Cells(i, 9), "(")
                        m = Split(x(1), ")")
                        n = m(0)
                        Set Cel = Feuil8.Range("A:A").Find(n, , , xlWhole)
                        If Not Cel Is Nothing Then Lig = Cel.Row
                        .Cells(i, a) = Right(Feuil8.Cells(Lig, 2), 2)
                        .Cells(i, a).Font.ColorIndex = 4  'met la couleur dans la cellule H
                        .Cells(i, a + 1) = Left(Feuil8.Cells(Lig, 2), 2)
                        .Cells(i, a + 1).Font.ColorIndex = 4  'met la couleur dans la cellule L
                    Else
                        x = Split(.Cells(i, 9), ",") ' on presume qu'on a une virgule
                        n = x(1)
                        Set Cel = Feuil8.Range("A:A").Find(n, , , xlWhole)
                        If Not Cel Is Nothing Then Lig = Cel.Row
                        .Cells(i, a) = Right(Feuil8.Cells(Lig, 2), 2)
                        .Cells(i, a).Font.ColorIndex = 4  'met la couleur dans la cellule H
                        .Cells(i, a + 1) = Left(Feuil8.Cells(Lig, 2), 2)
                        .Cells(i, a + 1).Font.ColorIndex = 4  'met la couleur dans la cellule L
                    End If
                End If
            Next a
        Next i
    End With
End Sub

Bonjour

    Sub Variable_type2() 'traitement de variables, pour cellules avec "L" suivit de  "H"  Papou
       Dim i&, fin&, a&, x As Variant, n$, m, Cel As Range, Lig&
        With Feuil6
            fin = .Range("A" & Rows.Count).End(xlUp).Row
            For i = 2 To fin
                For a = 4 To 5
If Not IsError(.Cells(i,a)) Then
                    If .Cells(i, a) = "L" Then  'on suppose que "H" est present dans la cellule de droite
                       If .Cells(i, 9) Like "*" & "(" & "*" Then 'si on a une parenthese
                           x = Split(.Cells(i, 9), "(")
                            m = Split(x(1), ")")
                            n = m(0)
                            Set Cel = Feuil8.Range("A:A").Find(n, , , xlWhole)
                            If Not Cel Is Nothing Then Lig = Cel.Row
                            .Cells(i, a) = Right(Feuil8.Cells(Lig, 2), 2)
                            .Cells(i, a).Font.ColorIndex = 4  'met la couleur dans la cellule H
                           .Cells(i, a + 1) = Left(Feuil8.Cells(Lig, 2), 2)
                            .Cells(i, a + 1).Font.ColorIndex = 4  'met la couleur dans la cellule L
                       Else
                            x = Split(.Cells(i, 9), ",") ' on presume qu'on a une virgule
                           n = x(1)
                            Set Cel = Feuil8.Range("A:A").Find(n, , , xlWhole)
                            If Not Cel Is Nothing Then Lig = Cel.Row
                            .Cells(i, a) = Right(Feuil8.Cells(Lig, 2), 2)
                            .Cells(i, a).Font.ColorIndex = 4  'met la couleur dans la cellule H
                           .Cells(i, a + 1) = Left(Feuil8.Cells(Lig, 2), 2)
                            .Cells(i, a + 1).Font.ColorIndex = 4  'met la couleur dans la cellule L
                       End If
                    End If
End If
                Next a
            Next i
        End With
    End Sub

Tout ca fonctionne!

J'aimerais bien un petit ajout a une macro afin de pouvoir mettre en couleur toute les cellules contenant le mot d'une cellule.

Les explications sont dans le fichier.

68capucin-v-48.zip (150.25 Ko)

Salut Banzai! je vais mettre ma derniere demande dans un nouveau post.

Rechercher des sujets similaires à "ignorer"