D
doublenico
Guest
Bonjour,
J'ai crée une macro mais on ne peut pas dire qu'elle soit optimisée.
Je vous l'explique.
Dans mon tableau, j'ai une liste d'item qui appartiennent chacun à une catégorie. Juste à côté, j'ai une colonne 'type d'item' qui prend les valeurs suivantes : R,I,E,N ou vide.
Lorsque cette colonne, contient des items ou le type d'item est R,I,E,N, il copie ces items et les met dans une autre feuille du classeur selon l'ordre de classement.
Comme j'ai réussi à le faire pour un type d'item, j'ai fait des copiés/collés, pour les autres types d'items mais ma macro est res longue.
Merci
Ma macro se lance en cliquant sur le bouton 'filtre'
En fait,
Ci-joint la macro :
Sub filtre()
'
' Macro1 Macro
' Macro enregistrée le 29/06/2005 par u032332
'
' Effacer les résultats précédents
Sheets('Synthese').Select
Columns('B').Select
Selection.Delete Shift:=xlToLeft
Sheets('Synthese').Select
Cells(5, 3).Select
ActiveCell.FormulaR1C1 = 'Inducteurs clés'
Selection.Font.Bold = True
With Selection.Font
.Name = 'Arial'
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleSingle
.ColorIndex = xlAutomatic
End With
Selection.Interior.ColorIndex = 34
i = 9
j = 7
While i <= 109
Sheets('Cahierdescharges').Select
If Cells(i, 5) = 'I' Then
Cells(i, 4).Select
Selection.Copy
Sheets('Synthese').Select
Cells(j, 3).Select
ActiveSheet.Paste
j = j + 1
Else
End If
i = i + 1
Wend
jj1 = j + 2
Sheets('Synthese').Select
Cells(jj1, 3).Select
ActiveCell.FormulaR1C1 = 'Nouveautés majeures'
Selection.Font.Bold = True
With Selection.Font
.Name = 'Arial'
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleSingle
.ColorIndex = xlAutomatic
End With
Selection.Interior.ColorIndex = 34
k1 = j + 4
i = 9
While i <= 109
Sheets('Cahierdescharges').Select
If Cells(i, 5) = 'N' Then
Cells(i, 4).Select
Selection.Copy
Sheets('Synthese').Select
Cells(k1, 3).Select
ActiveSheet.Paste
k1 = k1 + 1
Else
End If
i = i + 1
Wend
k2 = k1 + 4
jj2 = k1 + 2
Sheets('Synthese').Select
Cells(jj2, 3).Select
ActiveCell.FormulaR1C1 = 'Engagements majeurs'
Selection.Font.Bold = True
With Selection.Font
.Name = 'Arial'
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleSingle
.ColorIndex = xlAutomatic
End With
Selection.Interior.ColorIndex = 34
i = 9
While i <= 109
Sheets('Cahierdescharges').Select
If Cells(i, 5) = 'E' Then
Cells(i, 4).Select
Selection.Copy
Sheets('Synthese').Select
Cells(k2, 3).Select
ActiveSheet.Paste
k2 = k2 + 1
Else
End If
i = i + 1
Wend
k3 = k2 + 4
jj3 = k2 + 2
Sheets('Synthese').Select
Cells(jj3, 3).Select
ActiveCell.FormulaR1C1 = 'Risques, points durs à surveiller'
Selection.Font.Bold = True
With Selection.Font
.Name = 'Arial'
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleSingle
.ColorIndex = xlAutomatic
End With
Selection.Interior.ColorIndex = 34
i = 9
While i <= 109
Sheets('Cahierdescharges').Select
If Cells(i, 5) = 'R' Then
Cells(i, 4).Select
Selection.Copy
Sheets('Synthese').Select
Cells(k3, 3).Select
ActiveSheet.Paste
k3 = k3 + 1
Else
End If
i = i + 1
Wend
Sheets('Synthese').Select
Columns('C:C').EntireColumn.AutoFit
Columns('C:C').Select
With Selection
.HorizontalAlignment = xlLeft
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns('C').Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Columns('C:C').EntireColumn.AutoFit
Cells(5, 3).Select
Selection.HorizontalAlignment = xlCenter
Cells(jj1, 3).Select
Selection.HorizontalAlignment = xlCenter
Cells(jj2, 3).Select
Selection.HorizontalAlignment = xlCenter
Cells(jj3, 3).Select
Selection.HorizontalAlignment = xlCenter
Cells(1, 3).Select
End Sub
[file name=macro_20050928101156.zip size=22868]http://www.excel-downloads.com/components/com_simpleboard/uploaded/files/macro_20050928101156.zip[/file]
J'ai crée une macro mais on ne peut pas dire qu'elle soit optimisée.
Je vous l'explique.
Dans mon tableau, j'ai une liste d'item qui appartiennent chacun à une catégorie. Juste à côté, j'ai une colonne 'type d'item' qui prend les valeurs suivantes : R,I,E,N ou vide.
Lorsque cette colonne, contient des items ou le type d'item est R,I,E,N, il copie ces items et les met dans une autre feuille du classeur selon l'ordre de classement.
Comme j'ai réussi à le faire pour un type d'item, j'ai fait des copiés/collés, pour les autres types d'items mais ma macro est res longue.
Merci
Ma macro se lance en cliquant sur le bouton 'filtre'
En fait,
Ci-joint la macro :
Sub filtre()
'
' Macro1 Macro
' Macro enregistrée le 29/06/2005 par u032332
'
' Effacer les résultats précédents
Sheets('Synthese').Select
Columns('B').Select
Selection.Delete Shift:=xlToLeft
Sheets('Synthese').Select
Cells(5, 3).Select
ActiveCell.FormulaR1C1 = 'Inducteurs clés'
Selection.Font.Bold = True
With Selection.Font
.Name = 'Arial'
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleSingle
.ColorIndex = xlAutomatic
End With
Selection.Interior.ColorIndex = 34
i = 9
j = 7
While i <= 109
Sheets('Cahierdescharges').Select
If Cells(i, 5) = 'I' Then
Cells(i, 4).Select
Selection.Copy
Sheets('Synthese').Select
Cells(j, 3).Select
ActiveSheet.Paste
j = j + 1
Else
End If
i = i + 1
Wend
jj1 = j + 2
Sheets('Synthese').Select
Cells(jj1, 3).Select
ActiveCell.FormulaR1C1 = 'Nouveautés majeures'
Selection.Font.Bold = True
With Selection.Font
.Name = 'Arial'
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleSingle
.ColorIndex = xlAutomatic
End With
Selection.Interior.ColorIndex = 34
k1 = j + 4
i = 9
While i <= 109
Sheets('Cahierdescharges').Select
If Cells(i, 5) = 'N' Then
Cells(i, 4).Select
Selection.Copy
Sheets('Synthese').Select
Cells(k1, 3).Select
ActiveSheet.Paste
k1 = k1 + 1
Else
End If
i = i + 1
Wend
k2 = k1 + 4
jj2 = k1 + 2
Sheets('Synthese').Select
Cells(jj2, 3).Select
ActiveCell.FormulaR1C1 = 'Engagements majeurs'
Selection.Font.Bold = True
With Selection.Font
.Name = 'Arial'
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleSingle
.ColorIndex = xlAutomatic
End With
Selection.Interior.ColorIndex = 34
i = 9
While i <= 109
Sheets('Cahierdescharges').Select
If Cells(i, 5) = 'E' Then
Cells(i, 4).Select
Selection.Copy
Sheets('Synthese').Select
Cells(k2, 3).Select
ActiveSheet.Paste
k2 = k2 + 1
Else
End If
i = i + 1
Wend
k3 = k2 + 4
jj3 = k2 + 2
Sheets('Synthese').Select
Cells(jj3, 3).Select
ActiveCell.FormulaR1C1 = 'Risques, points durs à surveiller'
Selection.Font.Bold = True
With Selection.Font
.Name = 'Arial'
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleSingle
.ColorIndex = xlAutomatic
End With
Selection.Interior.ColorIndex = 34
i = 9
While i <= 109
Sheets('Cahierdescharges').Select
If Cells(i, 5) = 'R' Then
Cells(i, 4).Select
Selection.Copy
Sheets('Synthese').Select
Cells(k3, 3).Select
ActiveSheet.Paste
k3 = k3 + 1
Else
End If
i = i + 1
Wend
Sheets('Synthese').Select
Columns('C:C').EntireColumn.AutoFit
Columns('C:C').Select
With Selection
.HorizontalAlignment = xlLeft
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns('C').Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Columns('C:C').EntireColumn.AutoFit
Cells(5, 3).Select
Selection.HorizontalAlignment = xlCenter
Cells(jj1, 3).Select
Selection.HorizontalAlignment = xlCenter
Cells(jj2, 3).Select
Selection.HorizontalAlignment = xlCenter
Cells(jj3, 3).Select
Selection.HorizontalAlignment = xlCenter
Cells(1, 3).Select
End Sub
[file name=macro_20050928101156.zip size=22868]http://www.excel-downloads.com/components/com_simpleboard/uploaded/files/macro_20050928101156.zip[/file]