Code VBA ne fonctionne pas sur tous les PC

Bonjour à tous,

J'ai un problème sur un code VBA qui ne fonctionne pas d'un PC à l'autre.
Initialement, il fonctionnait sur mon PC fixe avec Excel 2019 et sur mon PC portable avec Excel 2013.
Le problème est qu'il tournait sur quelques autres PC au sein de mon entreprise, mais pas tous.
La version Excel et Windows est la même sur l'ensemble de ces ordinateurs.

Pour remettre un peu de contexte, c'est en Thaïlande et le fichier m'a été fourni par une entreprise aux US (je ne pense pas qu'il y ait de problème de compatibilité, mais sait-on jamais...).

J'ai récemment changé de version Excel sur mon PC portable pour passer à la 2021, et depuis je retrouve le même code erreur que sur le PC de mes collègues.

L'erreur est la suivante :

image

Vous trouverez ci-joint le fichier Excel.

Je vous remercie d'avance de votre aide !

Bonne journée,

Cordialement,

Rémi

Bonjour

De façon général le paramètre DefaultVerion ne sert pas à grand chose et peut poser problème

Le code n'est guère optimisé...

Edit : sans optimisation, juste correction. C'est bien un PB de langue qui impacte le nom de la nouvelle feuille et celle du champ Sum of Pct...

Sub PFMLoadvsCapacity()
'
' PFMLoadvsCapacity Macro
'
' Keyboard Shortcut: Ctrl+e
'
    Range("G15").Select
    Application.Goto Reference:="R1C8"
    ActiveCell.FormulaR1C1 = "Capacity"
    Columns("H:H").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Application.Goto Reference:="R1C8"
    ActiveCell.FormulaR1C1 = "Load"
    Range("H2").Select
    ActiveCell.FormulaR1C1 = "=IF(RC[-4]<>"""",RC[1],0)"
    Range("H2").Select
    Selection.Copy
    Range("H3").Select
    Range(Selection, Selection.End(xlDown)).Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    ActiveSheet.ListObjects("Table1").Name = "LvCTable"
    Application.CutCopyMode = False
    Sheets.Add
    WS = ActiveSheet.Name
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "LvCTable", Version:=8).CreatePivotTable TableDestination:=WS & "!R3C1", _
        TableName:="LvCPivotTable1", DefaultVersion:=8
    Sheets(WS).Cells(3, 1).Select
    With ActiveSheet.PivotTables("LvCPivotTable1")
        .ColumnGrand = True
        .HasAutoFormat = True
        .DisplayErrorString = False
        .DisplayNullString = True
        .EnableDrilldown = True
        .ErrorString = ""
        .MergeLabels = False
        .NullString = ""
        .PageFieldOrder = 2
        .PageFieldWrapCount = 0
        .PreserveFormatting = True
        .RowGrand = True
        .SaveData = True
        .PrintTitles = False
        .RepeatItemsOnEachPrintedPage = True
        .TotalsAnnotation = False
        .CompactRowIndent = 1
        .InGridDropZones = False
        .DisplayFieldCaptions = True
        .DisplayMemberPropertyTooltips = False
        .DisplayContextTooltips = True
        .ShowDrillIndicators = True
        .PrintDrillIndicators = False
        .AllowMultipleFilters = False
        .SortUsingCustomLists = True
        .FieldListSortAscending = False
        .ShowValuesRow = False
        .CalculatedMembersInFilters = False
        .RowAxisLayout xlCompactRow
    End With
    With ActiveSheet.PivotTables("LvCPivotTable1").PivotCache
        .RefreshOnFileOpen = False
        .MissingItemsLimit = xlMissingItemsDefault
    End With
    ActiveSheet.PivotTables("LvCPivotTable1").RepeatAllLabels xlRepeatLabels
    With ActiveSheet.PivotTables("LvCPivotTable1").PivotFields("ResourceName")
        .Orientation = xlRowField
        .Position = 1
    End With
    ActiveSheet.PivotTables("LvCPivotTable1").AddDataField ActiveSheet.PivotTables( _
        "LvCPivotTable1").PivotFields("Load"), "Sum of Load", xlSum
    ActiveSheet.PivotTables("LvCPivotTable1").AddDataField ActiveSheet.PivotTables( _
        "LvCPivotTable1").PivotFields("Capacity"), "Sum of Capacity", xlSum
    ActiveSheet.PivotTables("LvCPivotTable1").CalculatedFields.Add "Pct", _
        "=Load/Capacity", True
    ActiveSheet.PivotTables("LvCPivotTable1").AddDataField ActiveSheet.PivotTables( _
        "LvCPivotTable1").PivotFields("Pct"), "Sum of Pct"
    With ActiveSheet.PivotTables("LvCPivotTable1").PivotFields("Sum of Pct")
        .Caption = " L vs C %"
        .NumberFormat = "0%"
    End With
    With ActiveSheet.PivotTables("LvCPivotTable1").PivotFields("Sum of Capacity")
        .Caption = " Capacity"
        .NumberFormat = "0"
    End With
    With ActiveSheet.PivotTables("LvCPivotTable1").PivotFields("Sum of Load")
        .Caption = " Load"
        .NumberFormat = "0.0"
    End With
    With ActiveSheet.PivotTables("LvCPivotTable1").PivotFields("Date")
        .Orientation = xlColumnField
        .Position = 1
    End With
    ActiveSheet.PivotTables("LvCPivotTable1").PivotFields("Date").AutoGroup
    Range("B5").Select
    Selection.Group Start:=True, End:=True, By:=7, Periods:=Array(False, _
        False, False, True, False, False, False)
    ActiveSheet.PivotTables("LvCPivotTable1").PivotSelect "' L vs C %'", _
        xlDataAndLabel, True
    Application.CutCopyMode = False
    Selection.FormatConditions.AddDatabar
    Selection.FormatConditions(Selection.FormatConditions.Count).ShowValue = True
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1)
        .MinPoint.Modify newtype:=xlConditionValueAutomaticMin
        .MaxPoint.Modify newtype:=xlConditionValueAutomaticMax
    End With
    With Selection.FormatConditions(1).BarColor
        .Color = 13012579
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).BarFillType = xlDataBarFillSolid
    Selection.FormatConditions(1).Direction = xlContext
    Selection.FormatConditions(1).NegativeBarFormat.ColorType = xlDataBarColor
    Selection.FormatConditions(1).BarBorder.Type = xlDataBarBorderNone
    Selection.FormatConditions(1).AxisPosition = xlDataBarAxisAutomatic
    With Selection.FormatConditions(1).AxisColor
        .Color = 0
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).NegativeBarFormat.Color
        .Color = 255
        .TintAndShade = 0
    End With
'

    ActiveSheet.PivotTables("LvCPivotTable1").PivotSelect "' Load'", xlDataAndLabel, _
        True
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThick
    End With
    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
    Range("K19").Select
    ActiveSheet.PivotTables("LvCPivotTable1").PivotSelect "' Capacity'", _
        xlDataAndLabel, True
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ThemeColor = 2
        .TintAndShade = 4.99893185216834E-02
        .Weight = xlThin
    End With
    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
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    ActiveSheet.PivotTables("LvCPivotTable1").PivotSelect "' L vs C %'", _
        xlDataAndLabel, True
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ThemeColor = 2
        .TintAndShade = 4.99893185216834E-02
        .Weight = xlThin
    End With
    Selection.Borders(xlEdgeTop).LineStyle = xlNone
    Selection.Borders(xlEdgeBottom).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    ActiveSheet.PivotTables("LvCPivotTable1").MergeLabels = True
    Range("E2").Select

End Sub

Bonjour remhh, 78chris

Le problème vient pour moi du fait que vous avez des versions Excel Française et Anglaise

Je suis en train de regarder pour optimiser le code

A+

Bonjour Chris, Bruno,

Merci à vous deux pour votre point de vue.
Et en effet, il y a eu de nombreux problèmes engendrés par la langue sélectionnée.

Du coup, je percute, les PC sur lesquels le code fonctionnait étaient tous en anglais (PC des expatriés uniquement).

Je vous remercie pour votre aide et optimisation / correction du code !

Bonne journée

Rémi

Rechercher des sujets similaires à "code vba fonctionne pas tous"