Appliquer Macro sur Plusieurs Lignes

Fermé
freeycap Messages postés 87 Date d'inscription lundi 27 octobre 2014 Statut Membre Dernière intervention 3 septembre 2018 - 27 mars 2015 à 16:05
f894009 Messages postés 17205 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 19 octobre 2024 - 27 mars 2015 à 16:44
Bonjour,

J'ai une maco simple que j'utilise sur une ligne, la ligne 2 en l'occurence.
Je veux appliquer ma macro jusqu'à la ligne 11

Voici la ligne que j'ai ajouté que j'ai trouvé sur des forums, mais je n'arrive pas è bien l'utiliser :

'Répéter la macro jusqu'a la derniere ligne
derligne = Range("C" & Rows.Count).End(xlUp).Row + 1

J'aimerai comprendre la logique du compte de ligne... j'suis encore novice en VBA...

Ma macro est la suivante :

Sub TestQualif()

'Dim Nom As String
Nom = Cells(2, 1)

'Dim Prenom As String
Prenom = Cells(2, 2)

'Dim Note As Integer
Note = Cells(2, 3)

'Dim Quote As String
Quote = Cells(2, 4)

'Dim Age As Integer
Age = Cells(2, 5)

'Dim Origine As String
Origine = Cells(2, 6)

'Dim Langue1 As String
Langue1 = Cells(2, 7)

'Dim Langue2 As String
Langue2 = Cells(2, 8)

'Répéter la macro jusqu'a la derniere ligne
derligne = Range("C" & Rows.Count).End(xlUp).Row + 1

If Note >= 95 And Note <= 100 Then
Cells(2, 4) = "A+"
With Cells(2, 4)
.Interior.Color = RGB(0, 255, 0)
.Font.Color = RGB(0, 0, 0)
.Font.Bold = True
.HorizontalAlignment = xlCenter
End With

ElseIf Note >= 90 And Note <= 94.99 Then
Cells(2, 4) = "A-"
With Range("D2")
.Interior.Color = RGB(0, 255, 0)
.Font.Color = RGB(0, 0, 0)
.Font.Bold = True
.HorizontalAlignment = xlCenter
End With

ElseIf Note >= 85 And Note <= 89.99 Then
Cells(2, 4) = "B+"
With Range("D2")
.Interior.ColorIndex = 27
.Font.Color = RGB(0, 0, 0)
.Font.Bold = True
.HorizontalAlignment = xlCenter
End With

ElseIf Note >= 80 And Note <= 84.99 Then
Cells(2, 4) = "B-"
With Range("D2")
.Interior.ColorIndex = 27
.Font.Color = RGB(0, 0, 0)
.Font.Bold = True
.HorizontalAlignment = xlCenter
End With

ElseIf Note >= 75 And Note <= 79.99 Then
Cells(2, 4) = "C+"
With Range("D2")
.Interior.ColorIndex = 46
.Font.Color = RGB(255, 255, 255)
.Font.Bold = True
.HorizontalAlignment = xlCenter
End With

ElseIf Note >= 70 And Note <= 74.99 Then
Cells(2, 4) = "C-"
With Range("D2")
.Interior.ColorIndex = 46
.Font.Color = RGB(255, 255, 255)
.Font.Bold = True
.HorizontalAlignment = xlCenter
End With

ElseIf Note >= 60 And Note <= 69.99 Then
Cells(2, 4) = "D"
With Range("D2")
.Interior.Color = RGB(255, 0, 0)
.Font.Color = RGB(255, 255, 255)
.Font.Bold = True
.HorizontalAlignment = xlCenter
End With

ElseIf Note >= 0 And Note <= 59.99 Then
Cells(2, 4) = "E"
With Range("D2")
.Interior.Color = RGB(255, 0, 0)
.Font.Color = RGB(255, 255, 255)
.Font.Bold = True
.HorizontalAlignment = xlCenter
End With

End If

End Sub
A voir également:

1 réponse

f894009 Messages postés 17205 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 19 octobre 2024 1 709
27 mars 2015 à 16:44
Bonjour,

Sub TestQualif()
    'adaptez le nom de la feuille
    With Worksheets("feuil1")
        'Répéter la macro jusqu'a la derniere ligne
        derligne = .Range("C" & Rows.Count).End(xlUp).Row
        For lig = 2 To derlig
            Nom = .Cells(lig, 1)
            Prenom = .Cells(2, 2)
            Note = .Cells(2, 3)
            Quote = .Cells(2, 4)
            Age = .Cells(2, 5)
            Origine = .Cells(2, 6)
            Langue1 = .Cells(2, 7)
            Langue2 = .Cells(2, 8)
            If Note >= 95 And Note <= 100 Then
                .Cells(lig, 4) = "A+"
                With .Cells(lig, 4)
                .Interior.Color = RGB(0, 255, 0)
                .Font.Color = RGB(0, 0, 0)
                .Font.Bold = True
                .HorizontalAlignment = xlCenter
                End With
            ElseIf Note >= 90 And Note <= 94.99 Then
                .Cells(lig, 4) = "A-"
                With .Cells(lig, 4)
                    .Interior.Color = RGB(0, 255, 0)
                    .Font.Color = RGB(0, 0, 0)
                    .Font.Bold = True
                    .HorizontalAlignment = xlCenter
                End With
            ElseIf Note >= 85 And Note <= 89.99 Then
                .Cells(lig, 4) = "B+"
                With .Cells(lig, 4)
                    .Interior.ColorIndex = 27
                    .Font.Color = RGB(0, 0, 0)
                    .Font.Bold = True
                    .HorizontalAlignment = xlCenter
                End With
            ElseIf Note >= 80 And Note <= 84.99 Then
                .Cells(lig, 4) = "B-"
                With .Cells(lig, 4)
                    .Interior.ColorIndex = 27
                    .Font.Color = RGB(0, 0, 0)
                    .Font.Bold = True
                    .HorizontalAlignment = xlCenter
                End With
            ElseIf Note >= 75 And Note <= 79.99 Then
                .Cells(lig, 4) = "C+"
                With .Cells(lig, 4)
                    .Interior.ColorIndex = 46
                    .Font.Color = RGB(255, 255, 255)
                    .Font.Bold = True
                    .HorizontalAlignment = xlCenter
                End With
            ElseIf Note >= 70 And Note <= 74.99 Then
                .Cells(lig, 4) = "C-"
                With .Cells(lig, 4)
                    .Interior.ColorIndex = 46
                    .Font.Color = RGB(255, 255, 255)
                    .Font.Bold = True
                    .HorizontalAlignment = xlCenter
                End With
            ElseIf Note >= 60 And Note <= 69.99 Then
                .Cells(lig, 4) = "D"
                With .Cells(lig, 4)
                    .Interior.Color = RGB(255, 0, 0)
                    .Font.Color = RGB(255, 255, 255)
                    .Font.Bold = True
                    .HorizontalAlignment = xlCenter
                End With
            ElseIf Note >= 0 And Note <= 59.99 Then
                .Cells(lig, 4) = "E"
                With .Cells(lig, 4)
                    .Interior.Color = RGB(255, 0, 0)
                    .Font.Color = RGB(255, 255, 255)
                    .Font.Bold = True
                    .HorizontalAlignment = xlCenter
                End With
            End If
        Next lig
    End With
End Sub
0