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
| Sub trouvermax()
'Déclaration des variables
Dim nlecol As Integer, derli As Integer
Dim col1 As Integer, col2 As Integer, i As Integer
'Sélection de la feuille AAA
Sheets("AAA").Select
'Détermination de la colonne Max et de la dernière ligne
nlecol = ActiveSheet.UsedRange.Columns.Count + 1
derli = ActiveSheet.UsedRange.Rows.Count
Cells(1, nlecol).Formula = "Max"
'Détermination des colonnes East et Ouest
For i = 1 To nlecol - 1
If Cells(1, i).Value = "East" Then
col1 = i
End If
If Cells(1, i).Value = "Ouest" Then
col2 = i
End If
Next i
' Détermination et écriture du maximum cherché sur chaque ligne
For i = 2 To derli
Cells(i, nlecol).Value = Application.WorksheetFunction.Max(Cells(i, col1).Value, Cells(i, col2).Value)
Next i
End Sub |