Bonjour,
je reviens vers vous en ce moment décisif...
Non en fait j ai un ptit probleme: j ai fait une macro avec l'enregistreur de macro, n'ayant aucune idée comment écrire le code vba pour un tri sur couleur. J'ai une colonne dans laquelle se trouve des variables de médailles "Or",Argent,Bronze avec une couleur chacune. Je voudrais les trier d'or a bronze. Malheureusement quand j insere ma macro dans le code VBA de mon bouton déclencheur de déja beaucoup de choses, il y a 6 lignes qui ne sont pas prises en compte...
quelqu'un détecterait un probleme dans ce code? :
Private Sub CommandButton1_Click()
Dim i&, j&
Dim Tableau()
ReDim Tableau(1 To 5, 1 To 1)
Worksheets("Résultat").Range("A11:E65536").Cells.Clear
With Sheets("Inscr.")
For i = 2 To .Cells(Rows.Count, 2).End(xlUp).Row
For j = 20 To .Cells(1, Columns.Count).End(xlToLeft).Column
If .Cells(i, j).Value = "x" Then
ReDim Preserve Tableau(1 To 5, 1 To UBound(Tableau, 2) + 1)
Tableau(1, UBound(Tableau, 2)) = .Cells(i, 4)
Tableau(2, UBound(Tableau, 2)) = .Cells(i, 5)
Tableau(3, UBound(Tableau, 2)) = .Cells(i, 6)
Tableau(4, UBound(Tableau, 2)) = .Cells(1, j).Value
If .Cells(i, j + 1).Value = "" Then
Tableau(5, UBound(Tableau, 2)) = "Participation"
Else
Tableau(5, UBound(Tableau, 2)) = .Cells(i, j + 1).Value
End If
End If
Next j
Next i
End With
Cells(10, 1).Resize(UBound(Tableau, 2), UBound(Tableau, 1)) = Application.Transpose(Tableau)
Worksheets("Résultat").Cells.Columns.AutoFit
Worksheets("Résultat").Range("C11:C65536").HorizontalAlignment = xlCenter
Worksheets("Résultat").Range("C11:C65536").NumberFormat = "0#"
For Each Cell In Worksheets("Résultat").Range("E11:E65536")
If Cell.Value = "Arg" Or Cell.Value = "Argent" Or Cell.Value = "ARG" Then
Cell.Interior.ColorIndex = 15
End If
Next
For Each Cell In Worksheets("Résultat").Range("E11:E65536")
If Cell.Value = "Or" Or Cell.Value = "OR" Then
Cell.Interior.ColorIndex = 44
End If
Next
For Each Cell In Worksheets("Résultat").Range("E11:E65536")
If Cell.Value = "Bro" Or Cell.Value = "Bronze" Or Cell.Value = "BRO" Then
Cell.Interior.ColorIndex = 40
End If
Next
ActiveWorkbook.Worksheets("Résultat").AutoFilter.Sort.SortFields.Add(Range( _
"E1:E607"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color _
= RGB(255, 204, 0)
ActiveWorkbook.Worksheets("Résultat").AutoFilter.Sort.SortFields.Add(Range( _
"E1:E607"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color _
= RGB(192, 192, 192)
ActiveWorkbook.Worksheets("Résultat").AutoFilter.Sort.SortFields.Add(Range( _
"E1:E607"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color _
= RGB(255, 204, 153)
With ActiveWorkbook.Worksheets("Résultat").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End WithEnd Sub
Bonne journée et merci d'avance pour les réponses
je reviens vers vous en ce moment décisif...
Non en fait j ai un ptit probleme: j ai fait une macro avec l'enregistreur de macro, n'ayant aucune idée comment écrire le code vba pour un tri sur couleur. J'ai une colonne dans laquelle se trouve des variables de médailles "Or",Argent,Bronze avec une couleur chacune. Je voudrais les trier d'or a bronze. Malheureusement quand j insere ma macro dans le code VBA de mon bouton déclencheur de déja beaucoup de choses, il y a 6 lignes qui ne sont pas prises en compte...
quelqu'un détecterait un probleme dans ce code? :
Private Sub CommandButton1_Click()
Dim i&, j&
Dim Tableau()
ReDim Tableau(1 To 5, 1 To 1)
Worksheets("Résultat").Range("A11:E65536").Cells.Clear
With Sheets("Inscr.")
For i = 2 To .Cells(Rows.Count, 2).End(xlUp).Row
For j = 20 To .Cells(1, Columns.Count).End(xlToLeft).Column
If .Cells(i, j).Value = "x" Then
ReDim Preserve Tableau(1 To 5, 1 To UBound(Tableau, 2) + 1)
Tableau(1, UBound(Tableau, 2)) = .Cells(i, 4)
Tableau(2, UBound(Tableau, 2)) = .Cells(i, 5)
Tableau(3, UBound(Tableau, 2)) = .Cells(i, 6)
Tableau(4, UBound(Tableau, 2)) = .Cells(1, j).Value
If .Cells(i, j + 1).Value = "" Then
Tableau(5, UBound(Tableau, 2)) = "Participation"
Else
Tableau(5, UBound(Tableau, 2)) = .Cells(i, j + 1).Value
End If
End If
Next j
Next i
End With
Cells(10, 1).Resize(UBound(Tableau, 2), UBound(Tableau, 1)) = Application.Transpose(Tableau)
Worksheets("Résultat").Cells.Columns.AutoFit
Worksheets("Résultat").Range("C11:C65536").HorizontalAlignment = xlCenter
Worksheets("Résultat").Range("C11:C65536").NumberFormat = "0#"
For Each Cell In Worksheets("Résultat").Range("E11:E65536")
If Cell.Value = "Arg" Or Cell.Value = "Argent" Or Cell.Value = "ARG" Then
Cell.Interior.ColorIndex = 15
End If
Next
For Each Cell In Worksheets("Résultat").Range("E11:E65536")
If Cell.Value = "Or" Or Cell.Value = "OR" Then
Cell.Interior.ColorIndex = 44
End If
Next
For Each Cell In Worksheets("Résultat").Range("E11:E65536")
If Cell.Value = "Bro" Or Cell.Value = "Bronze" Or Cell.Value = "BRO" Then
Cell.Interior.ColorIndex = 40
End If
Next
ActiveWorkbook.Worksheets("Résultat").AutoFilter.Sort.SortFields.Add(Range( _
"E1:E607"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color _
= RGB(255, 204, 0)
ActiveWorkbook.Worksheets("Résultat").AutoFilter.Sort.SortFields.Add(Range( _
"E1:E607"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color _
= RGB(192, 192, 192)
ActiveWorkbook.Worksheets("Résultat").AutoFilter.Sort.SortFields.Add(Range( _
"E1:E607"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color _
= RGB(255, 204, 153)
With ActiveWorkbook.Worksheets("Résultat").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End WithEnd Sub
Bonne journée et merci d'avance pour les réponses