Macro bug sur filtrage TCD variable

Bonjour à toutes et tous,

Toute nouvelle sur ce forum, et bricoleuse non experte de VBA je viens solliciter vos connaissances car je bloque …

Je n'ai à priori pas trouvé de réponses ailleurs sur le forum

Mon problème :

  • j’ai un fichier excel incluant une macro, qui intervient sur un filtrage de TCD
  • cette macro bug car les cases à cocher du TCD sont variables (selon qui télécharge le fichier excel sur un site web, les données ne sont pas les mêmes = adaptées au profil utilisateur)

Savez-vous comment on peut ajuster un code VBA afin qu'il ne bloque pas si un des critères à sélectionner pour filtrer le TCD n'existe pas (= qu'il passe aux actions suivantes) ?

Je vous partage ci-dessous le code VBA

Je ne peux malheureusement pas vous partager le fichier pour des raisons RGPD et parce qu'il est extrêmement lourd à modifier/simplifier pour en faire un draft….sorry !

MERCI d'avance pour votre aide précieuse, car je dois rendre ce fichier rapidement…. !

Sub Macro1()

'

' Macro1 Macro

'

'

Application.DisplayAlerts = False

Application.ScreenUpdating = False

ActiveWorkbook.Unprotect Password:="TS2019YPR"

Sheets("FORMATION").Select

Sheets("TCD1").Visible = True

Sheets("TCD1").Select

Sheets("TCD2").Visible = True

Sheets("TCD2").Select

Sheets("DATABASE IMPORT TS").Visible = True

Sheets("DATABASE IMPORT TS").Select

Sheets("Database translation structure").Visible = True

Sheets("FORMATION").Select

Range("A1:K1").Select

Selection.Copy

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("EVOLUTION").Select

Range("A1:S1").Select

Application.CutCopyMode = False

Selection.Copy

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("TCD1").Select

Range("E4").Select

ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotCache.Refresh

ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields ("ID")

EnableMultiplePageItems = True

ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields ("ID")

CurrentPage = "(All)"

With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("ID")

.PivotItems("(blank)").Visible = False

.PivotItems("cases_EP_priorité_formation1").Visible = False

.PivotItems("cases_EP_priorité_formation2").Visible = False

.PivotItems("cases_EP_priorité_formation3").Visible = False

.PivotItems("prod_cases_EP_priorité_formation1").Visible = False

.PivotItems("prod_cases_EP_priorité_formation2").Visible = False

.PivotItems("prod_cases_EP_priorité_formation3").Visible = False

.PivotItems("texte_EP_objectif_formation1").Visible = False

.PivotItems("texte_EP_objectif_formation2").Visible = False

.PivotItems("texte_EP_objectif_formation3").Visible = False

.PivotItems("prod_texte_EP_objectif_formation1").Visible = False

.PivotItems("prod_texte_EP_objectif_formation2").Visible = False

.PivotItems("prod_texte_EP_objectif_formation3").Visible = False

.PivotItems("cases_EP_évolutions_année_passée").Visible = False

.PivotItems("prod_cases_EP_évolutions_significatives").Visible = False

.PivotItems("texte_EP_précision_évolutions_année_passée").Visible = False

.PivotItems("cases_changement_poste").Visible = False

End With

With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("ID")

.PivotItems("date_délai_changement_poste").Visible = False

.PivotItems("prod_cases_EP_changement_poste").Visible = False

.PivotItems("prod_date_EP_délai_changement_poste").Visible = False

.PivotItems("cases_évolutions_poste_actuel").Visible = False

.PivotItems("texte_attentes_évolutions_poste_actuel").Visible = False

.PivotItems("prod_texte_évolutions_poste").Visible = False

.PivotItems("prod_texte_précisions_évolutions_poste").Visible = False

End With

With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("ID")

.PivotItems("texte_EP_commentaire_manager").Visible = False

.PivotItems("prod_texte_EP_commentaire_manager").Visible = False

.PivotItems("cases_EP_perspectives_manager").Visible = False

.PivotItems("prod_cases_EP_perspectives_manager").Visible = False

.PivotItems("texte_EP_précisions_manager").Visible = False

.PivotItems("prod_texte_EP_précisions_manager").Visible = False

.PivotItems("cases_EP_fiche_fonction").Visible = False

.PivotItems("prod_cases_EP_fiche_fonction").Visible = False

.PivotItems("texte_poste_envisagé").Visible = False

.PivotItems("prod_texte_EP_poste_envisagé").Visible = False

End With

Range("A4").Select

Application.Goto Reference:="R4C1:R4000C9"

Selection.Copy

Sheets("FORMATION").Select

Range("A2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("DATABASE IMPORT TS").Select

Columns("M:M").Select

Application.CutCopyMode = False

Selection.Cut

Columns("A:A").Select

ActiveSheet.Paste

Sheets("FORMATION").Select

Range("J2:K2").Select

Selection.Copy

Application.Goto Reference:="R2C10:R40000C11"

ActiveSheet.Paste

Columns("J:K").Select

Selection.Copy

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Selection.Replace What:="#N/A", Replacement:="", LookAt:=xlPart, _

SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _

ReplaceFormat:=False

Selection.Replace What:=";", Replacement:="", LookAt:=xlPart, _

SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _

ReplaceFormat:=False

Columns("I:I").Select

Selection.Delete Shift:=xlToLeft

Sheets("FORMATION").Select

Application.Goto Reference:="R2C8:R5000C8"

With Selection.Interior

.Pattern = xlSolid

.PatternColorIndex = xlAutomatic

.ThemeColor = xlThemeColorDark1

.TintAndShade = -0.149998474074526

.PatternTintAndShade = 0

End With

Sheets("DATABASE IMPORT TS").Select

Columns("G:G").Select

Selection.Replace What:="attentes", Replacement:="précisions", LookAt:= _

xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _

ReplaceFormat:=False

Columns("M:M").Select

Selection.Delete Shift:=xlToLeft

Sheets("TCD2").Select

Range("I4").Select

Application.CutCopyMode = False

ActiveSheet.PivotTables("Tableau croisé dynamique2").PivotCache.Refresh

With ActiveSheet.PivotTables("Tableau croisé dynamique2").PivotFields("ID")

.PivotItems("(blank)").Visible = False

.PivotItems("texte_EP_proposition_formation1").Visible = False

.PivotItems("texte_EP_proposition_formation2").Visible = False

.PivotItems("texte_EP_proposition_formation3").Visible = False

.PivotItems("prod_texte_EP_proposition_formation2").Visible = False

.PivotItems("prod_texte_EP_proposition_formation3").Visible = False

.PivotItems("prod_texte_EP_proposition_formation1").Visible = False

.PivotItems("cases_EP_priorité_formation1").Visible = False

.PivotItems("cases_EP_priorité_formation2").Visible = False

.PivotItems("cases_EP_priorité_formation3").Visible = False

.PivotItems("prod_cases_EP_priorité_formation1").Visible = False

.PivotItems("prod_cases_EP_priorité_formation2").Visible = False

.PivotItems("prod_cases_EP_priorité_formation3").Visible = False

.PivotItems("texte_EP_objectif_formation1").Visible = False

.PivotItems("texte_EP_objectif_formation2").Visible = False

.PivotItems("texte_EP_objectif_formation3").Visible = False

.PivotItems("prod_texte_EP_objectif_formation1").Visible = False

End With

With ActiveSheet.PivotTables("Tableau croisé dynamique2").PivotFields("ID")

.PivotItems("prod_texte_EP_objectif_formation2").Visible = False

.PivotItems("prod_texte_EP_objectif_formation3").Visible = False

.PivotItems("cases_EP_évolutions_année_passée").Visible = False

.PivotItems("prod_cases_EP_évolutions_significatives").Visible = False

.PivotItems("texte_EP_précision_évolutions_année_passée").Visible = False

.PivotItems("cases_changement_poste").Visible = False

.PivotItems("date_délai_changement_poste").Visible = False

.PivotItems("prod_cases_EP_changement_poste").Visible = False

.PivotItems("prod_date_EP_délai_changement_poste").Visible = False

.PivotItems("cases_évolutions_poste_actuel").Visible = False

.PivotItems("texte_attentes_évolutions_poste_actuel").Visible = False

.PivotItems("prod_texte_évolutions_poste").Visible = False

.PivotItems("prod_texte_précisions_évolutions_poste").Visible = False

End With

With ActiveSheet.PivotTables("Tableau croisé dynamique2").PivotFields("ID")

.PivotItems("texte_EP_commentaire_manager").Visible = False

.PivotItems("prod_texte_EP_commentaire_manager").Visible = False

.PivotItems("cases_EP_perspectives_manager").Visible = False

.PivotItems("prod_cases_EP_perspectives_manager").Visible = False

.PivotItems("texte_EP_précisions_manager").Visible = False

.PivotItems("prod_texte_EP_précisions_manager").Visible = False

.PivotItems("texte_poste_envisagé").Visible = False

End With

With ActiveSheet.PivotTables("Tableau croisé dynamique2").PivotFields("ID")

.PivotItems("prod_texte_EP_poste_envisagé").Visible = False

.PivotItems("texte_précisions_évolutions_poste_actuel").Visible = False

End With

Range("A4").Select

Application.Goto Reference:="R4C1:R4000C9"

Selection.Copy

Sheets("EVOLUTION").Select

Range("A2").Select

ActiveSheet.Paste

Range("A4").Select

Application.Goto Reference:="R4C1:R4000C9"

Selection.Copy

Sheets("EVOLUTION").Select

Range("A2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("DATABASE IMPORT TS").Select

Columns("G:G").Select

Selection.Replace What:="précision_évolutions", Replacement:= _

"précisions_évolutions", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase _

:=False, SearchFormat:=False, ReplaceFormat:=False

Sheets("EVOLUTION").Select

Range("J2:S2").Select

Selection.Copy

Application.Goto Reference:="R2C10:R4000C19"

ActiveSheet.Paste

Sheets("EVOLUTION").Select

Range("I:I,J:J,L:L,O:O,R:R").Select

Range("R1").Activate

Selection.Replace What:=";", Replacement:="", LookAt:=xlPart, _

SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _

ReplaceFormat:=False

Sheets("EVOLUTION").Select

Columns("C:C").Select

Selection.Font.Bold = False

Selection.Font.Bold = True

Range("I2").Select

Application.Goto Reference:="R2C9:R4000C19"

Selection.Copy

ActiveWindow.SmallScroll Down:=-21

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Columns("I:S").Select

Selection.Replace What:="#N/A", Replacement:="", LookAt:=xlPart, _

SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _

ReplaceFormat:=False

Range("J:J,L:L,O:O,R:R").Select

Range("R1").Activate

Selection.Replace What:=";", Replacement:="", LookAt:=xlPart, _

SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _

ReplaceFormat:=False

Columns("H:H").Select

Selection.Delete Shift:=xlToLeft

Columns("A:R").Select

With Selection

.VerticalAlignment = xlCenter

.Orientation = 0

.AddIndent = False

.IndentLevel = 0

.ShrinkToFit = False

.ReadingOrder = xlContext

.MergeCells = False

End With

Range("H:I,K:K,M:N,Q:Q").Select

Range("Q1").Activate

With Selection

.HorizontalAlignment = xlGeneral

.VerticalAlignment = xlCenter

.Orientation = 0

.AddIndent = False

.IndentLevel = 0

.ShrinkToFit = False

.ReadingOrder = xlContext

.MergeCells = False

End With

With Selection

.HorizontalAlignment = xlCenter

.VerticalAlignment = xlCenter

.Orientation = 0

.AddIndent = False

.IndentLevel = 0

.ShrinkToFit = False

.ReadingOrder = xlContext

.MergeCells = False

Range("I2").Select

Application.Goto Reference:="R2C9:R4000C9"

With Selection.Interior

.Pattern = xlSolid

.PatternColorIndex = xlAutomatic

.ThemeColor = xlThemeColorDark1

.TintAndShade = -0.149998474074526

.PatternTintAndShade = 0

End With

ActiveWindow.SmallScroll Down:=-12

Range("K2").Select

Application.Goto Reference:="R2C11:R4000C11"

With Selection.Interior

.Pattern = xlSolid

.PatternColorIndex = xlAutomatic

.ThemeColor = xlThemeColorDark1

.TintAndShade = -0.149998474074526

.PatternTintAndShade = 0

End With

ActiveWindow.SmallScroll Down:=-21

Range("N2").Select

Application.Goto Reference:="R2C14:R4000C14"

With Selection.Interior

.Pattern = xlSolid

.PatternColorIndex = xlAutomatic

.ThemeColor = xlThemeColorDark1

.TintAndShade = -0.149998474074526

.PatternTintAndShade = 0

End With

ActiveWindow.SmallScroll Down:=-18

Range("Q2").Select

Application.Goto Reference:="R2C17:R4000C17"

With Selection.Interior

.Pattern = xlSolid

.PatternColorIndex = xlAutomatic

.ThemeColor = xlThemeColorDark1

.TintAndShade = -0.149998474074526

.PatternTintAndShade = 0

End With

Sheets("EVOLUTION").Select

Range("C1:C4000").SpecialCells(xlCellTypeBlanks).EntireRow.Delete

End With

Sheets("TCD1").Select

ActiveWindow.SelectedSheets.Delete

Sheets("TCD2").Select

ActiveWindow.SelectedSheets.Delete

Sheets("DATABASE IMPORT TS").Visible = False

Sheets("Database translation structure").Visible = False

ActiveWorkbook.Protect Password:="TS2019YPR"

Application.ScreenUpdating = True

Application.DisplayAlerts = True

End Sub

Bonjour & Bienvenue, userexcelVBA

Je suis désolé mais le code mis dans ton post ne me donne pas envie de m'arracher les cheveux pour le comprendre. Aucune règle respectée ( indentation et énormément de bout de code intitule), tu pourrais fournir un fichier anonymiser, tout en réduisant sa taille en ne laissant que quelques lignes, pour que l'on puisse comprendre ce que tu souhaites réellement.

Bonjour Florian53,

Je suis réellement novice et n'ai vraiment aucune idée de la laideur de mon code, désolée...

Je vais tester la solution On error resume next qui peut-être répondrait à ce bug…!

Quand une erreur intervient, il faut mieux la traiter que la snober

Rechercher des sujets similaires à "macro bug filtrage tcd variable"