Bonjour à tous,
Débutant en VBA, je bloque sur une erreur dont je n'arrive pas à connaître la cause.
Mon problème est de faire un tri dans une feuille sur 3 colonnes.
La plage doit être par définie par une variable entrée dans la feuille en "X28"
Je dois certainement avoir un problème dans le Range, mais je ne vois pas lequel.
Ci-dessous, la macro : (l'erreur est en rouge)
Sub Tri()
'
' Tri Macro
'
' Touche de raccourci du clavier: Ctrl+d
'
Dim a As Integer
Dim b As Integer
b = ActiveWorkbook.Sheets("Tabelle1").Range("X18").Value
For a = 2 To b
If Cells(a, 3) <> " " Then
ActiveWorkbook.Worksheets("Tabelle1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Tabelle1").Sort.SortFields.Add Key:=Range(Cells(2, 4), Cells(b, 4)).Select _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Tabelle1").Sort.SortFields.Add Key:=Range(Cells(2, 5), Cells(b, 5)).Select _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Tabelle1").Sort.SortFields.Add Key:=Range(Cells(2, 6), Cells(b, 6)) _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Tabelle1").Sort
.SetRange Range("B2:V51")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Else
End If
Next a
End Sub
Merci de votre aide !