Appliquer Macro sur Plusieurs Lignes
freeycap
Messages postés
87
Statut
Membre
-
f894009 Messages postés 17417 Date d'inscription Statut Membre Dernière intervention -
f894009 Messages postés 17417 Date d'inscription Statut Membre Dernière intervention -
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
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:
- Appliquer Macro sur Plusieurs Lignes
- Telecharger macro convertir chiffre en lettre excel - Télécharger - Tableur
- Télécharger macro convertir chiffre en lettre excel - Télécharger - Tableur
- Écrire plusieurs lignes dans une cellule excel mac - Guide
- Desinstaller application sur windows - Guide
- Jitbit macro recorder - Télécharger - Confidentialité
1 réponse
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