XL 2013 Macro créé sous 2013 qui ne fonctionne pas sous 2010

perrin

XLDnaute Nouveau
Bonjour,
J'ai créé une macro sur Excel 2013.
Je souhaite que ma collaboratrice s'occupe de cette mise à jour hebdomadaire mais son poste est équipé de Excel 2010 et ma macro bloque dès le début (en rouge)


Sub IMPORT()
'
' IMPORT Macro
'
Sheets("feuil1").Select
Range("A4:i4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents


Windows("ExportFINCDD.xls").Activate
Range("a1").Select
Selection.AutoFilter
ActiveSheet.Range("$a$1:$BG$22").AutoFilter Field:=29, Criteria1:="="


Y a-t-il une manip a faire dans le fichier pour que cela fonction sur excel 2010 ?

Merci d'avance pour votre aide.
Cordialement
Delphine
 

Robert

XLDnaute Barbatruc
Repose en paix
Bonjour Perrin, bonjour le forum,

La règle d'or en VBA c'est d'éviter autant que tu le peux les Select / Activate. Essaie comme ça :

VB:
Sub IMPORT()
Sheets("feuil1").Range("A4:I4").End(xlDown).ClearContents
Workbooks("ExportFINCDD.xls").Activate
ActiveSheet.Range("A1").AutoFilter
ActiveSheet.Range("A1:BG22").AutoFilter Field:=29, Criteria1:="="
End Sub
 

perrin

XLDnaute Nouveau
Bonjour,
merci pour votre retour si rapide ;-)
J'avoue ne pas avoir tout compris, et en modifiant ma macro comme indiqué par Robert, ça plante ... je pense qurtout que je en vous ai pas donné toutes les infos ...

Voici la macro en totalité ... c'est une macro enregistrée automatiquement et retravaillée ensuite.
Pas d'inquiétude, je n'ai rien touché sur la fin (au niveau de la mise en page) pour le moment ...
Concrètement que compile les infos d'un fichier de base (export CDD) dans un autre fichier pour faire un suivi (suivi CDD)
Merci pour aide.
Delphine

Sub IMPORT()
'
' IMPORT Macro
'
Sheets("feuil1").Select
Range("A4:i4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents


Windows("ExportFINCDD.xls").Activate
Range("a1").Select
Selection.AutoFilter
ActiveSheet.Range("$a$1:$BG$22").AutoFilter Field:=29, Criteria1:="="
Columns("D:D").Select
Application.CutCopyMode = False
Selection.Copy
Windows("suivi CDD.xlsm").Activate
Range("A3").Select
ActiveSheet.Paste

Windows("ExportFINCDD.xls").Activate
Columns("F:g").Select
Application.CutCopyMode = False
Selection.Copy
Windows("suivi CDD.xlsm").Activate
Range("B3").Select
ActiveSheet.Paste

Windows("ExportFINCDD.xls").Activate
Columns("R:R").Select
Application.CutCopyMode = False
Selection.Copy
Windows("suivi CDD.xlsm").Activate
Range("D3").Select
ActiveSheet.Paste
Windows("ExportFINCDD.xls").Activate
Columns("T:T").Select
Application.CutCopyMode = False
Selection.Copy
Windows("suivi CDD.xlsm").Activate
Range("E3").Select
ActiveSheet.Paste
Windows("ExportFINCDD.xls").Activate
Columns("V:V").Select
Application.CutCopyMode = False
Selection.Copy
Windows("suivi CDD.xlsm").Activate
Range("F3").Select
ActiveSheet.Paste
Windows("ExportFINCDD.xls").Activate
Columns("AA:AA").Select
Application.CutCopyMode = False
Selection.Copy
Windows("suivi CDD.xlsm").Activate
Range("G3").Select
ActiveSheet.Paste
Windows("ExportFINCDD.xls").Activate
Columns("AC:AC").Select
Application.CutCopyMode = False
Selection.Copy
Windows("suivi CDD.xlsm").Activate
Range("H3").Select
ActiveSheet.Paste



Range("I3").Select
Selection.Style = "RowLevel_4"
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
ActiveCell.FormulaR1C1 = "SUITE A DONNER"
Rows("3:3").Select
Selection.Font.Bold = True
Selection.Font.Size = 12
Selection.Font.Size = 14
Selection.Font.Size = 12
Selection.Copy
Application.CutCopyMode = False
Range("I3").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -4.99893185216834E-02
.PatternTintAndShade = 0
End With
Range("A3").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Cells.Select
Cells.EntireColumn.AutoFit
Range("H3:I3").Select
Range(Selection, Selection.End(xlDown)).Select
With Selection
.HorizontalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("G:G").ColumnWidth = 12.71
Columns("G:H").Select
Selection.ColumnWidth = 15.14
Range("I1").Select
Columns("I:I").ColumnWidth = 43
Cells.Select
Selection.ColumnWidth = 13.71
Cells.EntireRow.AutoFit
Range("C14").Select
Columns("C:C").ColumnWidth = 19.29
Rows("14:14").EntireRow.AutoFit
Range("G13").Select

'TRI'

Range("H8").Select
ActiveWorkbook.Worksheets("Feuil1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Feuil1").Sort.SortFields.Add Key:=Range("H8"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Feuil1").Sort
.SetRange Range("A3:I37")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

End Sub
 

Robert

XLDnaute Barbatruc
Repose en paix
Bonjour le fil, bonjour le forum,

Ton code modifié (tu corrigeras les incohérences de report de colonnes et ajoutera le tri final) :

VB:
Sub IMPORT()
Dim CD As Workbook
Dim OD As Worksheet
Dim DLD As Long
Dim CS As Workbook
Dim OS As Worksheet
Dim DLS As Long

Set CD = ThisWorkbook
Set OD = CD.Worksheets("Feuil1")
DLD = Application.Rows.Count
OD.Range("A4:I" & DLD).Clear
Set CS = Workbooks("ExportFINCDD.xls")
Set OS = CS.Worksheets("A")
DLS = OS.Range("A1").CurrentRegion.Rows.Count
OS.Range("A1").AutoFilter
OS.Range("A1:BG22").AutoFilter Field:=29, Criteria1:="="
OS.Range("D2:D" & DLS).Copy OD.Range("A4")
OS.Range("E2:E" & DLS).Copy OD.Range("B4")
OS.Range("R2:R" & DLS).Copy OD.Range("D4")
OS.Range("T2:T" & DLS).Copy OD.Range("E4")
OS.Range("V2:V" & DLS).Copy OD.Range("F4")
OS.Range("AA2:AA" & DLS).Copy OD.Range("G4")
OS.Range("AC2:AC" & DLS).Copy OD.Range("H4")
OD.Range("I3").Style = "RowLevel_4"
With OD.Range("I3").Interior
    .Pattern = xlNone
    .TintAndShade = 0
    .PatternTintAndShade = 0
End With
With OD.Range("I3")
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlCenter
    .WrapText = True
    .Orientation = 0
    .AddIndent = False
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
End With
OD.Range("I3").Value = "SUITE A DONNER"
With OD.Rows("3:3")
    .Font.Bold = True
    .Font.Size = 12
    .Font.Size = 14
    .Font.Size = 12
    .Copy
    .Select
End With
With OD.Range("I3").Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorDark1
    .TintAndShade = -4.99893185216834E-02
    .PatternTintAndShade = 0
End With
DLD = OD.Cells(Application.Rows.Count, "A").End(xlUp).Row
With OD.Range("A3:I" & DLD)
    .Borders(xlDiagonalDown).LineStyle = xlNone
    .Borders(xlDiagonalUp).LineStyle = xlNone
End With
With OD.Range("A3:I" & DLD).Borders(xlEdgeLeft)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
End With
With OD.Range("A3:I" & DLD).Borders(xlEdgeTop)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
End With
With OD.Range("A3:I" & DLD).Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
End With
With OD.Range("A3:I" & DLD).Borders(xlEdgeRight)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
End With
With OD.Range("A3:I" & DLD).Borders(xlInsideVertical)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
End With
With OD.Range("A3:I" & DLD).Borders(xlInsideHorizontal)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
End With
OD.Cells.EntireColumn.AutoFit
With OD.Range("H3:I" & DLD)
    .HorizontalAlignment = xlCenter
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
End With
OD.Columns.ColumnWidth = 13.71
OD.Cells.EntireRow.AutoFit
OD.Columns("G:G").ColumnWidth = 12.71
OD.Columns("G:H").ColumnWidth = 15.14
OD.Columns("I:I").ColumnWidth = 43
OD.Columns("C:C").ColumnWidth = 19.29
OD.Rows("14:14").EntireRow.AutoFit
End Sub
 
Dernière édition:

SETRAT

XLDnaute Nouveau
suite à cet échange qui date de pas mal de temps après correction du fichier, aujourd'hui je me retrouve avec un message de débogage lorsque je veux faire ma macro :

je ne parviens pas à vous envoyer l'imprime écran de l'erreur, voici un copier coller :
en bleu c'est l'erreur qui à été surligner en jaune dans mon fichier
Sub IMPORT()
'
' IMPORT Macro
'
Dim CD As Workbook
Dim OD As Worksheet
Dim DLD As Long
Dim CS As Workbook
Dim OS As Worksheet
Dim DLS As Long

Set CD = ThisWorkbook
Set OD = CD.Worksheets("Feuil1")
DLD = Application.Rows.Count
OD.Range("A4:I" & DLD).Clear
Set CS = Workbooks("ExportFINCDD.xls")
Set OS = CS.Worksheets("A")
DLS = OS.Range("A1").CurrentRegion.Rows.Count
OS.Range("A1").AutoFilter
 

SETRAT

XLDnaute Nouveau
Bonjour à tous et merci merci pour vos réponse,
JM27 oui pour tes 3 questions
Patrick toulon, oui également
herve62, mon fichier à bien l'extension .xls je dois la modifier?
Pourtant dans la macro c'est .xls
voir captures écran ci jointes
 

Pièces jointes

  • Capture.PNG
    Capture.PNG
    20.8 KB · Affichages: 15
  • Capture1.PNG
    Capture1.PNG
    11.4 KB · Affichages: 14

Discussions similaires

Réponses
2
Affichages
728
Réponses
14
Affichages
1 K
Réponses
38
Affichages
4 K

Statistiques des forums

Discussions
312 207
Messages
2 086 234
Membres
103 162
dernier inscrit
fcfg