Bonjour, J'ai créé une macro qui me permet de créer plusieurs onglets en fonction d'une liste et d'y coller une partie de la BDD d'origine avec un filtre avancé dessus.
la macro fonctionne bien seulement lorsque je change la BDD elle ne fonctionne plus et ce même si la BDD est plus petite. Excel se met à mouliner et il me dit que je n'ai pas assez de ressource.
en fait sur ma BDD de + de 3000 lignes il y en a 5 qui si je les supprime ou les efface font planter Excel...
Je ne peux pas vous mettre à dispo le fichier Excel car les données sont confidentielles.
Avez vous déjà eu ce genre de cas?
Voici le code de la macro :
Sub interco2()
Application.ScreenUpdating = False
Application.Calculation = xlManual
'suppression feuille
Dim Compteur As Integer, Nom As String
Application.DisplayAlerts = False
For Compteur = Worksheets.Count To 1 Step -1
Nom = Sheets(Compteur).Name
Select Case Nom
Case "Détail produits", "Taux de change", "Nouveaux", "To Do", "Flux", "ICP Total", "Format ICP"
Case Else
Sheets(Compteur).Delete
End Select
Next Compteur
Application.DisplayAlerts = True
'affichage de toutes les feuilles
Sheets("Conversion nouveaux produits").Visible = True
Sheets("Conversion nouveaux produits").Select
Sheets("Flux").Visible = True
Sheets("Conversion nouveaux produits").Select
Sheets("Taux de change").Visible = True
Sheets("Conversion nouveaux produits").Select
Sheets("Nomenclature produits Horizon").Visible = True
Sheets("Conversion nouveaux produits").Select
Sheets("Format ICP").Visible = True
Sheets("Conversion nouveaux produits").Select
ActiveWorkbook.RefreshAll
'Création feuille
Application.Calculation = xlManual
Sheets("Conversion nouveaux produits").Select
Dim c As Range
For Each c In Range("J4:J100")
Nom = c.Value
If Nom <> "" Then
Sheets.Add Count:=1, after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = Nom
' filtre avancé
Sheets("Détail produits").Select
Range("BW2").Select
ActiveCell.FormulaR1C1 = Nom
Range("B4:BI4").Select
Range("BI4").Activate
Application.CutCopyMode = False
Application.CutCopyMode = False
Dim myRange As Range
Set myRange = Range("B4:BI" & Range("B4").End(xlDown).Row)
myRange.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:= _
Range("BL1S2"), CopyToRange:=Range("BL4S4"), Unique:=False
Range("BL5S5").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWindow.SmallScroll Down:=3
Selection.Cut
Sheets(Nom).Select
Range("B5").Select
ActiveSheet.Paste
'Mise en page
Sheets("Détail produits").Select
Range("B2:BI4").Select
Selection.Copy
Sheets(Nom).Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Détail produits").Select
Columns("B:BI").Select
Range("BI1").Activate
Selection.Copy
Sheets(Nom).Select
Columns("B:BI").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Columns("A:A").Select
Selection.ColumnWidth = 0.9
Rows("1:1").Select
Selection.RowHeight = 9#
Sheets("Format ICP").Select
Range("BJ2:BQ5").Select
Selection.Copy
Sheets(Nom).Select
Range("BJ2").Select
ActiveSheet.Paste
Range("BJ5:BQ5").Select
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("BJ5:BQ20000")
Range("BJ5:BQ20000").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ThemeColor = 2
.TintAndShade = 0
.Weight = xlMedium
End With
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlMedium
End With
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("BJ5").Select
Range("B5:B20000").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Columns("C:C").Select
Selection.EntireColumn.Hidden = True
Columns("G:I").Select
Selection.EntireColumn.Hidden = True
Columns("M:BI").Select
Selection.EntireColumn.Hidden = True
Range("BJ5").Select
ActiveWindow.DisplayGridlines = False
ActiveWindow.FreezePanes = True
End If
Next c
' ICP Total
Sheets("ICP Total").Select
Cells.Select
Selection.Delete Shift:=xlUp
' filtre avancé
Sheets("Détail produits").Select
Range("BW2").Select
Selection.ClearContents
Range("B4:BI4").Select
Range("BI4").Activate
Application.CutCopyMode = False
Application.CutCopyMode = False
myRange.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:= _
Range("BL1S2"), CopyToRange:=Range("BL4S4"), Unique:=False
Range("BL5S5").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWindow.SmallScroll Down:=3
Selection.Cut
Sheets("ICP Total").Select
Range("B5").Select
ActiveSheet.Paste
'Mise en page
Sheets("Détail produits").Select
Range("B2:BI4").Select
Selection.Copy
Sheets("ICP Total").Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Détail produits").Select
Columns("B:BI").Select
Range("BI1").Activate
Selection.Copy
Sheets("ICP Total").Select
Columns("B:BI").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Columns("A:A").Select
Selection.ColumnWidth = 0.9
Rows("1:1").Select
Selection.RowHeight = 9#
Sheets("Format ICP").Select
Range("BJ2:BQ5").Select
Selection.Copy
Sheets("ICP Total").Select
Range("BJ2").Select
ActiveSheet.Paste
Range("BJ5:BQ5").Select
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("BJ5:BQ20000")
Range("BJ5:BQ20000").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ThemeColor = 2
.TintAndShade = 0
.Weight = xlMedium
End With
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlMedium
End With
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("BJ5").Select
Range("B5:B20000").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Columns("C:C").Select
Selection.EntireColumn.Hidden = True
Columns("G:I").Select
Selection.EntireColumn.Hidden = True
Columns("N:BI").Select
Selection.EntireColumn.Hidden = True
Columns("M:M").Select
Selection.Cut
Columns("D").Select
Selection.Insert Shift:=xlToRight
Rows("4:4").Select
Selection.AutoFilter
ActiveWorkbook.Worksheets("ICP Total").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("ICP Total").Sort.SortFields.Add Key:=Range( _
"D51026"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("ICP Total").Sort
.SetRange Range("B4:BT1026")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Columns("D").EntireColumn.AutoFit
Range("BJ5").Select
ActiveWindow.DisplayGridlines = False
ActiveWindow.FreezePanes = True
'Cacher les feuilles
Sheets("Conversion nouveaux produits").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Flux").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Taux de change").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Nomenclature produits Horizon").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Format ICP").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("ICP Total").Select
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
Sheets("Détail produits").Select
Range("b2").Select
ICP.Hide
End Sub
la macro fonctionne bien seulement lorsque je change la BDD elle ne fonctionne plus et ce même si la BDD est plus petite. Excel se met à mouliner et il me dit que je n'ai pas assez de ressource.
en fait sur ma BDD de + de 3000 lignes il y en a 5 qui si je les supprime ou les efface font planter Excel...
Je ne peux pas vous mettre à dispo le fichier Excel car les données sont confidentielles.
Avez vous déjà eu ce genre de cas?
Voici le code de la macro :
Sub interco2()
Application.ScreenUpdating = False
Application.Calculation = xlManual
'suppression feuille
Dim Compteur As Integer, Nom As String
Application.DisplayAlerts = False
For Compteur = Worksheets.Count To 1 Step -1
Nom = Sheets(Compteur).Name
Select Case Nom
Case "Détail produits", "Taux de change", "Nouveaux", "To Do", "Flux", "ICP Total", "Format ICP"
Case Else
Sheets(Compteur).Delete
End Select
Next Compteur
Application.DisplayAlerts = True
'affichage de toutes les feuilles
Sheets("Conversion nouveaux produits").Visible = True
Sheets("Conversion nouveaux produits").Select
Sheets("Flux").Visible = True
Sheets("Conversion nouveaux produits").Select
Sheets("Taux de change").Visible = True
Sheets("Conversion nouveaux produits").Select
Sheets("Nomenclature produits Horizon").Visible = True
Sheets("Conversion nouveaux produits").Select
Sheets("Format ICP").Visible = True
Sheets("Conversion nouveaux produits").Select
ActiveWorkbook.RefreshAll
'Création feuille
Application.Calculation = xlManual
Sheets("Conversion nouveaux produits").Select
Dim c As Range
For Each c In Range("J4:J100")
Nom = c.Value
If Nom <> "" Then
Sheets.Add Count:=1, after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = Nom
' filtre avancé
Sheets("Détail produits").Select
Range("BW2").Select
ActiveCell.FormulaR1C1 = Nom
Range("B4:BI4").Select
Range("BI4").Activate
Application.CutCopyMode = False
Application.CutCopyMode = False
Dim myRange As Range
Set myRange = Range("B4:BI" & Range("B4").End(xlDown).Row)
myRange.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:= _
Range("BL1S2"), CopyToRange:=Range("BL4S4"), Unique:=False
Range("BL5S5").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWindow.SmallScroll Down:=3
Selection.Cut
Sheets(Nom).Select
Range("B5").Select
ActiveSheet.Paste
'Mise en page
Sheets("Détail produits").Select
Range("B2:BI4").Select
Selection.Copy
Sheets(Nom).Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Détail produits").Select
Columns("B:BI").Select
Range("BI1").Activate
Selection.Copy
Sheets(Nom).Select
Columns("B:BI").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Columns("A:A").Select
Selection.ColumnWidth = 0.9
Rows("1:1").Select
Selection.RowHeight = 9#
Sheets("Format ICP").Select
Range("BJ2:BQ5").Select
Selection.Copy
Sheets(Nom).Select
Range("BJ2").Select
ActiveSheet.Paste
Range("BJ5:BQ5").Select
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("BJ5:BQ20000")
Range("BJ5:BQ20000").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ThemeColor = 2
.TintAndShade = 0
.Weight = xlMedium
End With
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlMedium
End With
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("BJ5").Select
Range("B5:B20000").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Columns("C:C").Select
Selection.EntireColumn.Hidden = True
Columns("G:I").Select
Selection.EntireColumn.Hidden = True
Columns("M:BI").Select
Selection.EntireColumn.Hidden = True
Range("BJ5").Select
ActiveWindow.DisplayGridlines = False
ActiveWindow.FreezePanes = True
End If
Next c
' ICP Total
Sheets("ICP Total").Select
Cells.Select
Selection.Delete Shift:=xlUp
' filtre avancé
Sheets("Détail produits").Select
Range("BW2").Select
Selection.ClearContents
Range("B4:BI4").Select
Range("BI4").Activate
Application.CutCopyMode = False
Application.CutCopyMode = False
myRange.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:= _
Range("BL1S2"), CopyToRange:=Range("BL4S4"), Unique:=False
Range("BL5S5").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWindow.SmallScroll Down:=3
Selection.Cut
Sheets("ICP Total").Select
Range("B5").Select
ActiveSheet.Paste
'Mise en page
Sheets("Détail produits").Select
Range("B2:BI4").Select
Selection.Copy
Sheets("ICP Total").Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Détail produits").Select
Columns("B:BI").Select
Range("BI1").Activate
Selection.Copy
Sheets("ICP Total").Select
Columns("B:BI").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Columns("A:A").Select
Selection.ColumnWidth = 0.9
Rows("1:1").Select
Selection.RowHeight = 9#
Sheets("Format ICP").Select
Range("BJ2:BQ5").Select
Selection.Copy
Sheets("ICP Total").Select
Range("BJ2").Select
ActiveSheet.Paste
Range("BJ5:BQ5").Select
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("BJ5:BQ20000")
Range("BJ5:BQ20000").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ThemeColor = 2
.TintAndShade = 0
.Weight = xlMedium
End With
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlMedium
End With
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("BJ5").Select
Range("B5:B20000").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Columns("C:C").Select
Selection.EntireColumn.Hidden = True
Columns("G:I").Select
Selection.EntireColumn.Hidden = True
Columns("N:BI").Select
Selection.EntireColumn.Hidden = True
Columns("M:M").Select
Selection.Cut
Columns("D").Select
Selection.Insert Shift:=xlToRight
Rows("4:4").Select
Selection.AutoFilter
ActiveWorkbook.Worksheets("ICP Total").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("ICP Total").Sort.SortFields.Add Key:=Range( _
"D51026"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("ICP Total").Sort
.SetRange Range("B4:BT1026")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Columns("D").EntireColumn.AutoFit
Range("BJ5").Select
ActiveWindow.DisplayGridlines = False
ActiveWindow.FreezePanes = True
'Cacher les feuilles
Sheets("Conversion nouveaux produits").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Flux").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Taux de change").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Nomenclature produits Horizon").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Format ICP").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("ICP Total").Select
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
Sheets("Détail produits").Select
Range("b2").Select
ICP.Hide
End Sub