XL 2010 report de feuilles

poipoi

XLDnaute Occasionnel
Bonjour
encore moi... et pourtant mine de rien, j'essaie avant de poster..
mon souci est le suivant:
sur la feuil1 j'ai un parc de véhicules avec marques en colonnes et noms de véhicules en lignes
et ensuite, une feuille par "marque."
comment faire pour que sur les feuilles "marques" n'apparaissent que les véhicules de cette marque, sans lignes d'une autre marque et sans lignes vides
ça doit se faire sans macro je pense, avec une formule, mais là je cale!

encore merci
(un jour, il faudra que je fasse une grande fête pour remercier tous ceux, ils sont nombreux, qui m'ont aidé... mais faut que j'économise d'abord)
 

Pièces jointes

  • parc.xls
    37 KB · Affichages: 32
Dernière édition:

Jocelyn

XLDnaute Barbatruc
Bonjour le Forum,
Bonjour poipoi,

un essai en ficchier joint je n'ai fait que la feuille renault a toi de voir si cela convient et si oui a toi de voir si tu peux le refaire sur la feuille peugeot

Cordialement

EDIT Bonjour l'ami JHA :), désolé pour la collision pas rafraichi mais content de te croiser
 

Pièces jointes

  • parc.xls
    38.5 KB · Affichages: 31

poipoi

XLDnaute Occasionnel
Bonjour JHA, Bonjour Jocelyn

déjà MERCI, oui un grand merci à chaque fois pour la rapidité, le disponibilité et le "savoir donner".

Je subodorai bien la fonction INDEX et EQUIV mais j'ai du mal à l'appliquer, à l'adapter à mes tableaux.
Il va falloir me pencher réellement et d'une manière plus approfondie sur ces fonctions qui doivent être la solution à pas mal de mes soucis.
quoiqu'il en soit je vous dis à bientôt, et si vous passez pas loin de chez moi, il y aura toujours à grignoter ou on se débrouillera.
 

klin89

XLDnaute Accro
Bonsoir à tous, :)

une autre façon de procéder :
VB:
Option Explicit
Sub test()
Dim a, w(), i As Long, j As Long, n As Long, dico As Object, e
    Set dico = CreateObject("Scripting.Dictionary")
    dico.CompareMode = 1
    With Sheets("parc").Range("a1").CurrentRegion
        a = .Value
        For j = 3 To UBound(a, 2)
            For i = 2 To UBound(a, 1)
                If a(i, j) <> "" Then
                    If Not dico.exists(a(1, j)) Then
                        ReDim w(1 To 3, 1 To 2)
                        w(1, 1) = "N°"
                        w(2, 1) = "Modèle"
                        w(3, 1) = a(1, j)
                    Else
                        w = dico(a(1, j))
                        ReDim Preserve w(1 To UBound(w), 1 To UBound(w, 2) + 1)
                    End If
                    n = n + 1
                    w(1, UBound(w, 2)) = n
                    w(2, UBound(w, 2)) = a(i, 2)
                    w(3, UBound(w, 2)) = a(i, j)
                    dico(a(1, j)) = w
                End If
            Next
            n = 0
        Next
        Application.ScreenUpdating = False
        For Each e In dico
            If Not IsSheetExists(e) Then
                Sheets.Add(after:=Sheets(Sheets.Count)).Name = e
            End If
            With Sheets(e)
                .Cells.Clear
                With .Cells(1).Resize(UBound(dico(e), 2), UBound(dico(e), 1))
                    .Value = Application.Transpose(dico(e))
                    .Font.Name = "calibri"
                    .Font.Size = 10
                    .VerticalAlignment = xlCenter
                    .HorizontalAlignment = xlCenter
                    .BorderAround Weight:=xlThin
                    .Borders(xlInsideVertical).Weight = xlThin
                    With .Rows(1)
                        .Font.Size = 10
                        .Interior.ColorIndex = 36
                        .BorderAround Weight:=xlThin
                    End With
                End With
            End With
        Next
    End With
    Set dico = Nothing
    Application.ScreenUpdating = True
End Sub

Function IsSheetExists(ByVal sn As String) As Boolean
    On Error Resume Next
    IsSheetExists = Len(Sheets(sn).Name)
End Function
klin89
 

poipoi

XLDnaute Occasionnel
Bonjour Klin89, le forum

et ça marche du feu de Dieu!!! super
du coup j'me dis "tiens je vais corser l'affaire", non pas par plaisir mais parce que mon tableau évolue plus vite que mes capacités !! (et de loin)
voir en pièce jointe si vous avez du temps, s'il pleut dehors ou si votre télé est en panne,
en tous les cas, merci pour votre patience.
 

Pièces jointes

  • parc2.xls
    42 KB · Affichages: 46

klin89

XLDnaute Accro
Re poipoi, :)

Une question : à quoi correspondent les nombres figurant en feuille "parc"

A tester avec le fichier du post #7
VB:
Option Explicit
Sub test()
Dim a, i As Long, j As Long, n As Long, e, s, dico As Object
    a = Sheets("parc").[a1].CurrentRegion.Value
    Set dico = CreateObject("Scripting.Dictionary")
    dico.Comparemode = 1
    For j = 3 To UBound(a, 2)
        If a(1, j) = "" Then a(1, j) = a(1, j - 1)
        If Not dico.exists(a(1, j)) Then
            Set dico(a(1, j)) = CreateObject("Scripting.Dictionary")
            dico(a(1, j)).Comparemode = 1
        End If
        For i = 3 To UBound(a, 1)
            If Not dico(a(1, j)).exists(a(i, 2)) Then
                Set dico(a(1, j))(a(i, 2)) = CreateObject("Scripting.Dictionary")
            End If
            If Not dico(a(1, j))(a(i, 2)).exists(a(2, j)) Then
                dico(a(1, j))(a(i, 2))(a(2, j)) = a(i, j)
            End If
        Next
    Next
    For Each e In dico.keys
        For Each s In dico.Item(e).keys
            If Application.Count(dico(e).Item(s).items) = 0 Then dico(e).Remove s
        Next
    Next
    For Each e In dico.keys
        If dico(e).Count = 0 Then
            dico.Remove e
        End If
    Next
    If dico.Count = 0 Then MsgBox "aucune donnée à traiter": Exit Sub
    Application.ScreenUpdating = False
    For Each e In dico
        If Not IsSheetExists(e) Then
            Sheets.Add(after:=Sheets(Sheets.Count)).Name = e
        End If
        With Sheets(e)
            n = 0
            .Cells(1).CurrentRegion.Clear
            .Cells(1, 2).Value = "Marque": .Cells(1, 3).Value = e
            .Cells(2, 2).Value = "Cylindrée"
            .Cells(2, 3).Resize(, dico(e).items()(0).Count).Value = dico(e).items()(0).keys()
            .Cells(3, 2).Resize(dico(e).Count).Value = Application.Transpose(dico(e).keys)
            For Each s In dico.Item(e).keys
                .Cells(3 + n, 1).Value = n + 1
                .Cells(3 + n, 3).Resize(, dico(e).Item(s).Count).Value = dico(e).Item(s).items
                n = n + 1
            Next
            With .Cells(1).CurrentRegion
                .Font.Name = "calibri"
                .Font.Size = 10
                .VerticalAlignment = xlCenter
                .HorizontalAlignment = xlCenter
                .BorderAround Weight:=xlThin
                .Borders(xlInsideVertical).Weight = xlHairline
                With .Rows("1:2")
                    .BorderAround Weight:=xlThin
                    With .Offset(, 1).Resize(, .Columns.Count - 1)
                        .Interior.ColorIndex = 11
                        .Font.ColorIndex = 2
                        .Columns.ColumnWidth = 12
                    End With
                End With
                With .Rows(1)
                    With .Offset(, 2).Resize(, .Columns.Count - 2)
                        .HorizontalAlignment = xlCenterAcrossSelection
                    End With
                End With
            End With
        End With
    Next
    Set dico = Nothing
    Application.ScreenUpdating = True
End Sub

Function IsSheetExists(ByVal txt As String) As Boolean
    On Error Resume Next
    IsSheetExists = Len(Sheets(txt).Name)
    On Error GoTo 0
End Function
klin89
 

poipoi

XLDnaute Occasionnel
Bonjour Klin89, le forum
merci beaucoup.... et quel boulot tu as fait!!!! chapeau.
En effet, les numéros correspondent à des numéros d'identification qu'il me faudrait pouvoir garder sur les feuilles Renault et Peugeot,
Nous aurions alors, par ex.: feuille "Peugeot", la 208 avec son n°2 et juste au dessous, la 3007 et son n°4.

En fait c'est que je souhaiterais!

merci vraiment Klin89
 

klin89

XLDnaute Accro
Re poipoi :)

le code réajusté :
VB:
Option Explicit
Sub test()
Dim a, i As Long, j As Long, n As Long, e, s, dico As Object, txt As String
    a = Sheets("parc").[a1].CurrentRegion.Value
    Set dico = CreateObject("Scripting.Dictionary")
    dico.Comparemode = 1
    For j = 3 To UBound(a, 2)
        If a(1, j) = "" Then a(1, j) = a(1, j - 1)
        If Not dico.exists(a(1, j)) Then
            Set dico(a(1, j)) = CreateObject("Scripting.Dictionary")
            dico(a(1, j)).Comparemode = 1
        End If
        For i = 3 To UBound(a, 1)
            txt = Join$(Array(a(i, 1), a(i, 2)), "---") 'la modif
            If Not dico(a(1, j)).exists(txt) Then
                Set dico(a(1, j))(txt) = CreateObject("Scripting.Dictionary")
            End If
            If Not dico(a(1, j))(txt).exists(a(2, j)) Then
                dico(a(1, j))(txt)(a(2, j)) = a(i, j)
            End If
        Next
    Next
    For Each e In dico.keys
        For Each s In dico.Item(e).keys
            If Application.Count(dico(e).Item(s).items) = 0 Then dico(e).Remove s
        Next
    Next
    For Each e In dico.keys
        If dico(e).Count = 0 Then
            dico.Remove e
        End If
    Next
    If dico.Count = 0 Then MsgBox "aucune donnée à traiter": Exit Sub
    Application.ScreenUpdating = False
    For Each e In dico.keys
        If Not IsSheetExists(e) Then
            Sheets.Add(after:=Sheets(Sheets.Count)).Name = e
        End If
        With Sheets(e)
            n = 0
            .Cells(1).CurrentRegion.Clear
            .Cells(1, 2).Value = "Marque": .Cells(1, 3).Value = e
            .Cells(2, 2).Value = "Cylindrée"
            .Cells(2, 3).Resize(, dico(e).items()(0).Count).Value = dico(e).items()(0).keys()
            For Each s In dico.Item(e).keys
                .Cells(3 + n, 1).Value = Split(s, "---")(0) 'la modif
                .Cells(3 + n, 2).Value = Split(s, "---")(1) 'la modif
                .Cells(3 + n, 3).Resize(, dico(e).Item(s).Count).Value = dico(e).Item(s).items
                n = n + 1
            Next
            With .Cells(1).CurrentRegion
                .Font.Name = "calibri"
                .Font.Size = 10
                .VerticalAlignment = xlCenter
                .HorizontalAlignment = xlCenter
                .BorderAround Weight:=xlThin
                .Borders(xlInsideVertical).Weight = xlHairline
                With .Rows("1:2")
                    .BorderAround Weight:=xlThin
                    With .Offset(, 1).Resize(, .Columns.Count - 1)
                        .Interior.ColorIndex = 11
                        .Font.ColorIndex = 2
                        .Columns.ColumnWidth = 12
                    End With
                End With
                With .Rows(1)
                    With .Offset(, 2).Resize(, .Columns.Count - 2)
                        .HorizontalAlignment = xlCenterAcrossSelection
                    End With
                End With
            End With
        End With
    Next
    Set dico = Nothing
    Application.ScreenUpdating = True
End Sub

Function IsSheetExists(ByVal txt As String) As Boolean
    On Error Resume Next
    IsSheetExists = Len(Sheets(txt).Name)
    On Error GoTo 0
End Function
klin89
 

poipoi

XLDnaute Occasionnel
Re Klin89, le forum
avec toutes mes excuses je reviens vers toi, pensant que j'arriverai seul à adapter ton code sur mon projet.
eh ben non.. même en repérant et en remplaçant dans le code, les noms de feuilles, les "coordonnées" des cellules, rien n'y fait.
Tout cela est encore trop complexe pour moi.
Alors voici le véritable classeur qui me sert de compta pour une petite association .

(Klin89, je comprendrai bien volontiers la lassitude!)
 

Pièces jointes

  • COMPTES_ESSAI_2017.xlsm
    123.4 KB · Affichages: 30

klin89

XLDnaute Accro
Re poipoi :)

Le code adapté au fichier du post #13
VB:
Option Explicit
Sub test()
Dim a, i As Long, j As Long, n As Long, e, s, dico As Object, txt As String
    a = Sheets("GRAND LIVRE").[a1].CurrentRegion.Value
    Set dico = CreateObject("Scripting.Dictionary")
    dico.Comparemode = 1
    For j = 14 To UBound(a, 2)
        If j <> 14 And j <> 36 And j <> 37 And j <> 52 Then
            If a(1, j) = "" Then a(1, j) = a(1, j - 1)
            If Not dico.exists(a(1, j)) Then
                Set dico(a(1, j)) = CreateObject("Scripting.Dictionary")
            End If
            For i = 4 To UBound(a, 1) - 2
                txt = Join$(Array(a(i, 1), a(i, 6)), "|")
                If Not dico(a(1, j)).exists(txt) Then
                    Set dico(a(1, j))(txt) = CreateObject("Scripting.Dictionary")
                    dico(a(1, j))(txt).Comparemode = 1
                End If
                If Not dico(a(1, j))(txt).exists(a(2, j)) Then
                    dico(a(1, j))(txt)(a(2, j)) = a(i, j)
                End If
            Next
        End If
    Next
    For Each e In dico.keys
        For Each s In dico.Item(e).keys
            If Application.Count(dico(e).Item(s).items) = 0 Then dico(e).Remove s
        Next
    Next
    For Each e In dico.keys
        If dico(e).Count = 0 Then
            dico.Remove e
        End If
    Next
    If dico.Count = 0 Then MsgBox "aucune donnée à traiter": Set dico = Nothing: Exit Sub
    With Application
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
    End With
    For Each e In dico.keys
        On Error Resume Next
        Application.DisplayAlerts = False
        Sheets(e).Delete
        Sheets.Add(Before:=Sheets("GRAND LIVRE")).Name = e
        On Error GoTo 0
        With Sheets(e)
            n = 0
            .Cells(1, 3).Value = e
            .Cells(2, 1).Resize(, 2).Value = Array("N° piéces", "Libellés")
            .Cells(2, 3).Resize(, dico(e).items()(0).Count).Value = dico(e).items()(0).keys()
            For Each s In dico.Item(e).keys
                .Cells(3 + n, 1).Resize(, 2).Value = Array(Split(s, "|")(0), Split(s, "|")(1))
                .Cells(3 + n, 3).Resize(, dico(e).Item(s).Count).Value = dico(e).Item(s).items
                n = n + 1
            Next
            With .Cells(1)
                With .CurrentRegion
                    With .Offset(.Rows.Count)
                        .Columns(1).Resize(1, 2).Value = Array("---", "Totaux")
                        'les sommes en bout de colonnes
                        .Columns(3).Resize(1, .Columns.Count - 2).Formula = "=sum(r3c:r[-1]c)"
                    End With
                    With .Offset(, .Columns.Count)
                        .Rows(2).Resize(1, 1).Value = "Total " & e
                        'les sommes en bout de lignes
                        .Rows(3).Resize(.Rows.Count - 1, 1).Formula = "=sum(rc3:rc[-1])"
                    End With
                End With
                With .CurrentRegion
                    .VerticalAlignment = xlCenter
                    With .Font
                        .Name = "calibri"
                        .Size = 9
                    End With
                    With .Rows(1)
                        .RowHeight = 22
                        With .Offset(, 2).Resize(, .Columns.Count - 3)
                            .HorizontalAlignment = xlCenterAcrossSelection
                            With .Font
                                .Size = 12: .Bold = True
                                If e = "DEPENSES" Then
                                    .ColorIndex = 53
                                Else
                                    .ColorIndex = 55
                                End If
                            End With
                        End With
                    End With
                    With .Offset(1).Resize(.Rows.Count - 1)
                        .BorderAround Weight:=xlThin
                        .Borders(xlInsideVertical).Weight = xlThin
                        With .Rows(1)
                            .RowHeight = 20
                            .HorizontalAlignment = xlCenter
                            .Font.Size = 10
                            .BorderAround Weight:=xlThin
                            With .Offset(, 2).Resize(, .Columns.Count - 3)
                                With .Interior
                                    If e = "DEPENSES" Then
                                        .ColorIndex = 40
                                    Else
                                        .ColorIndex = 37
                                    End If
                                End With
                            End With
                        End With
                        With .Rows(.Rows.Count)
                            .BorderAround Weight:=xlThin
                            With .Offset(, 2).Resize(, .Columns.Count - 3)
                                With .Interior
                                    If e = "DEPENSES" Then
                                        .ColorIndex = 40
                                    Else
                                        .ColorIndex = 37
                                    End If
                                End With
                            End With
                        End With
                        With .Columns(1).Resize(, 2)
                            .HorizontalAlignment = xlCenter
                        End With
                        With .Offset(1, 2).Resize(.Rows.Count - 1, .Columns.Count - 2)
                            .NumberFormat = "#,##0.00_ ;[Red]-#,##0.00"
                            With .Resize(, .Columns.Count - 1)
                                .Borders(xlInsideVertical).Weight = xlHairline
                            End With
                        End With
                    End With
                    .Columns.AutoFit
                End With
            End With
        End With
    Next
    Sheets("GRAND LIVRE").Move Before:=Sheets(dico.keys()(0))
    Set dico = Nothing
    With Application
        .Calculation = xlCalculationAutomatic
        .ScreenUpdating = True
    End With
End Sub
klin89
 

Discussions similaires

Membres actuellement en ligne

Statistiques des forums

Discussions
312 105
Messages
2 085 350
Membres
102 870
dernier inscrit
Armisa