Problème d'extraction de tableau

Bonjour j'ai un problème avec le code suivant. je cherche a sortir deux tableaux (un en fonction du temps selon les mois et phase° et un tableau en taux de production par moi selon différentes phases.

J'arrive bien a ressortir le tableau mais il ma manque la colonne RAPPORT a chaque fois (il me la comptabilise dans le total par contre). Je deviens chèvre. Pouvez vous m'aidez SVP ?

Sub EtatGlobal()
    Dim wsGlobal As Worksheet
    Dim deSheets As Collection
    Dim phaseNames As Variant
    Dim monthNames As Variant
    Dim phaseData(1 To 12, 1 To 7) As Double ' Adjusted for RAPPORT column
    Dim totalRow As Long, totalCol As Long
    Dim selectedYear As Long
    Dim phaseRow As Long, monthCol As Long

    ' Phase and month names
    phaseNames = Array("DEMARRAGE MISSION", "SYNOPTIQUE", "ETUDES TERRAIN", "BUREAU ETUDES", "MAP", "RAPPORT")
    monthNames = Array("Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre")

    ' Get year from MENU sheet
    On Error Resume Next
    selectedYear = ThisWorkbook.Sheets("MENU").Range("G15").Value
    If selectedYear = 0 Then
        MsgBox "Veuillez saisir une année valide dans la cellule G15 de la feuille MENU.", vbCritical
        Exit Sub
    End If
    On Error GoTo 0

    ' Create or clear "Etat Global" sheet
    On Error Resume Next
    Application.DisplayAlerts = False
    Worksheets("Etat Global").Delete
    Application.DisplayAlerts = True
    On Error GoTo 0

    Set wsGlobal = ThisWorkbook.Sheets.Add
    wsGlobal.Name = "Etat Global"

    ' Headers for phases and months
    wsGlobal.Cells(1, 1).Value = "Mois"
    For phaseRow = LBound(phaseNames) To UBound(phaseNames)
        wsGlobal.Cells(1, phaseRow + 2).Value = phaseNames(phaseRow)
    Next phaseRow
    wsGlobal.Cells(1, UBound(phaseNames) + 2).Value = "Total"

    ' Add month names to the first column
    For monthCol = LBound(monthNames) To UBound(monthNames)
        wsGlobal.Cells(monthCol + 2, 1).Value = monthNames(monthCol)
    Next monthCol
    wsGlobal.Cells(14, 1).Value = "Total"

    ' Collect all sheets starting with DE0
    Set deSheets = New Collection
    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Sheets
        If Left(ws.Name, 3) = "DE0" Then
            deSheets.Add ws
        End If
    Next ws

    ' Loop through DE0 sheets to consolidate data
    Dim phaseRanges As Variant
    phaseRanges = Array("A13:A22", "A25:A34", "A37:A46", "A49:A58", "A61:A70", "A73:A82")
    Dim daysRanges As Variant
    daysRanges = Array("H13:H22", "H25:H34", "H37:H46", "H49:H58", "H61:H70", "H73:H82")
    Dim productionRanges As Variant
    productionRanges = Array("I13:I22", "I25:I34", "I37:I46", "I49:I58", "I61:I70", "I73:I82")

    Dim cell As Range
    For Each ws In deSheets
        For phaseRow = LBound(phaseNames) To UBound(phaseNames)
            For Each cell In ws.Range(phaseRanges(phaseRow))
                If IsDate(cell.Value) And Year(cell.Value) = selectedYear Then
                    monthCol = Month(cell.Value)
                    phaseData(monthCol, phaseRow + 1) = phaseData(monthCol, phaseRow + 1) + Val(ws.Range(daysRanges(phaseRow))(cell.Row - ws.Range(phaseRanges(phaseRow)).Row + 1).Value)
                End If
            Next cell
        Next phaseRow
    Next ws

    ' Populate the global report
    For monthCol = 1 To 12
        For phaseRow = LBound(phaseNames) To UBound(phaseNames)
            wsGlobal.Cells(monthCol + 1, phaseRow + 2).Value = phaseData(monthCol, phaseRow + 1)
        Next phaseRow

        ' Add totals for each month
        wsGlobal.Cells(monthCol + 1, UBound(phaseNames) + 2).Value = WorksheetFunction.Sum(Application.Index(phaseData, monthCol))
    Next monthCol

    ' Add totals for all phases
    For phaseRow = LBound(phaseNames) To UBound(phaseNames)
        wsGlobal.Cells(14, phaseRow + 2).Value = WorksheetFunction.Sum(Application.Index(phaseData, 0, phaseRow + 1))
    Next phaseRow

    ' Add grand total
    wsGlobal.Cells(14, UBound(phaseNames) + 2).Value = WorksheetFunction.Sum(wsGlobal.Range(wsGlobal.Cells(2, UBound(phaseNames) + 2), wsGlobal.Cells(13, UBound(phaseNames) + 2)))

    MsgBox "Etat Global généré avec succès pour l'année " & selectedYear & "!"
End Sub

je rajoute mon fichier (> onglet MENU > BOUTON ETTA GLOBAL)

hier

bonjour,

Dans mon environnement, je détecte un problème avec les indices des tableaux VBA qui commencent avec l'indice 0 quand ils reçoivent le résultat d'une fonction array et un tableau qui commence avec des indices 1 quand il est défini explicitement. Ce qui chez moi donne des problèmes d'alignement des tableaux quand on veut les transférer dans des cellules de la feuille ETAT GLOBAL, je ne sais pas si c'est ce problème que tu rencontres, mais voici une solution (vite faite) à ce problème.

Merci ça marche nickel :-)

Rechercher des sujets similaires à "probleme extraction tableau"