IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Somme d'un tableau à une dimension vba [XL-2013]


Sujet :

Macros et VBA Excel

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    technicien selection
    Inscrit en
    Novembre 2014
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Saône et Loire (Bourgogne)

    Informations professionnelles :
    Activité : technicien selection
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Novembre 2014
    Messages : 7
    Points : 1
    Points
    1
    Par défaut Somme d'un tableau à une dimension vba
    Bonjour, je débute dans les macros excel mon code est assez approximatif mais je me debrouille pour faire ce que je veux.

    Je vous explique ce que je recherche a faire:
    je souhaiterais à terme insérer des sauts de pages à des endroits spécifique de ma feuille excel. Il doivents s'inserer après une serie qui fait au maximum 40 lignes. Il doit calculer pour que la plage ne soit pas coupé ( donc ne pas dépasser 40 lignes ) mais mettre le plus possible de plages.
    Je pense que je vous ait perdu. Je vous montre mon code, je n'est pour l'instant mis que le test la macro n'insere pas de saut de page je mettrai la fonction après :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    Dim tab1(40, 2) As Single, tab2(200) As Single, max As Integer, col As Integer, lig As Integer, test As Integer
     
    Rows("7:7").Select
        Selection.Insert Shift:=xlDown
        Range("i6").Select
    Do Until ActiveCell = ""
    Erase tab1
    y = y + 1
    x = 39
    actcellrow = ActiveCell.Row
    actcellcol = ActiveCell.Column
    Cells(actcellrow, actcellcol).Select
    max = 0
    Do
    ActiveCell.Offset(0, 1).Select
        Selection.End(xlDown).Select
        Selection.End(xlDown).Select
        ActiveCell.Offset(1, -1).Select
        max = max + 1
    Loop Until ActiveCell.Address = Cells(181, 9).Address
    MsgBox (max)
    If max < 39 Then x = max - 1
    MsgBox (x)
    Cells(actcellrow, actcellcol).Select
    For i = 0 To x
    ActiveCell.Offset(0, 1).Select
        Selection.End(xlDown).Select
        Selection.End(xlDown).Select
        ActiveCell.Offset(1, -1).Select
        tab1(i, 0) = ActiveCell.Value
        tab1(i, 1) = ActiveCell.Row
        tab1(i, 2) = ActiveCell.Column
     
        Next
        If tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) + tab1(20, 0) + tab1(21, 0) + tab1(22, 0) + tab1(23, 0) + tab1(24, 0) + tab1(25, 0) + tab1(26, 0) + tab1(27, 0) + tab1(28, 0) + tab1(29, 0) + tab1(30, 0) + tab1(31, 0) + tab1(32, 0) + tab1(33, 0) + tab1(34, 0) + tab1(35, 0) + tab1(36, 0) + tab1(37, 0) + tab1(38, 0) + tab1(39, 0) < 40 Then
        col = tab1(39, 1) - 1
        Cells(col, 9).Select
        ActiveCell.Offset(0, 1).Select
        Selection.End(xlLeft).Select
        tab2(y) = ActiveCell.Value
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) + tab1(20, 0) + tab1(21, 0) + tab1(22, 0) + tab1(23, 0) + tab1(24, 0) + tab1(25, 0) + tab1(26, 0) + tab1(27, 0) + tab1(28, 0) + tab1(29, 0) + tab1(30, 0) + tab1(31, 0) + tab1(32, 0) + tab1(33, 0) + tab1(34, 0) + tab1(35, 0) + tab1(36, 0) + tab1(37, 0) + tab1(38, 0) < 40 Then
        col = tab1(38, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) + tab1(20, 0) + tab1(21, 0) + tab1(22, 0) + tab1(23, 0) + tab1(24, 0) + tab1(25, 0) + tab1(26, 0) + tab1(27, 0) + tab1(28, 0) + tab1(29, 0) + tab1(30, 0) + tab1(31, 0) + tab1(32, 0) + tab1(33, 0) + tab1(34, 0) + tab1(35, 0) + tab1(36, 0) + tab1(37, 0) < 40 Then
        col = tab1(37, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) + tab1(20, 0) + tab1(21, 0) + tab1(22, 0) + tab1(23, 0) + tab1(24, 0) + tab1(25, 0) + tab1(26, 0) + tab1(27, 0) + tab1(28, 0) + tab1(29, 0) + tab1(30, 0) + tab1(31, 0) + tab1(32, 0) + tab1(33, 0) + tab1(34, 0) + tab1(35, 0) + tab1(36, 0) < 40 Then
        col = tab1(36, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) + tab1(20, 0) + tab1(21, 0) + tab1(22, 0) + tab1(23, 0) + tab1(24, 0) + tab1(25, 0) + tab1(26, 0) + tab1(27, 0) + tab1(28, 0) + tab1(29, 0) + tab1(30, 0) + tab1(31, 0) + tab1(32, 0) + tab1(33, 0) + tab1(34, 0) + tab1(35, 0) < 40 Then
        col = tab1(35, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) + tab1(20, 0) + tab1(21, 0) + tab1(22, 0) + tab1(23, 0) + tab1(24, 0) + tab1(25, 0) + tab1(26, 0) + tab1(27, 0) + tab1(28, 0) + tab1(29, 0) + tab1(30, 0) + tab1(31, 0) + tab1(32, 0) + tab1(33, 0) + tab1(34, 0) < 40 Then
        col = tab1(34, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) + tab1(20, 0) + tab1(21, 0) + tab1(22, 0) + tab1(23, 0) + tab1(24, 0) + tab1(25, 0) + tab1(26, 0) + tab1(27, 0) + tab1(28, 0) + tab1(29, 0) + tab1(30, 0) + tab1(31, 0) + tab1(32, 0) + tab1(33, 0) < 40 Then
        col = tab1(33, 1) - 1
        Cells(col, 9).Select
    ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) + tab1(20, 0) + tab1(21, 0) + tab1(22, 0) + tab1(23, 0) + tab1(24, 0) + tab1(25, 0) + tab1(26, 0) + tab1(27, 0) + tab1(28, 0) + tab1(29, 0) + tab1(30, 0) + tab1(31, 0) + tab1(32, 0) < 40 Then
       col = tab1(32, 1) - 1
        Cells(col, 9).Select
    ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) + tab1(20, 0) + tab1(21, 0) + tab1(22, 0) + tab1(23, 0) + tab1(24, 0) + tab1(25, 0) + tab1(26, 0) + tab1(27, 0) + tab1(28, 0) + tab1(29, 0) + tab1(30, 0) + tab1(31, 0) < 40 Then
         col = tab1(31, 1) - 1
        Cells(col, 9).Select
    ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) + tab1(20, 0) + tab1(21, 0) + tab1(22, 0) + tab1(23, 0) + tab1(24, 0) + tab1(25, 0) + tab1(26, 0) + tab1(27, 0) + tab1(28, 0) + tab1(29, 0) + tab1(30, 0) < 40 Then
        col = tab1(30, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) + tab1(20, 0) + tab1(21, 0) + tab1(22, 0) + tab1(23, 0) + tab1(24, 0) + tab1(25, 0) + tab1(26, 0) + tab1(27, 0) + tab1(28, 0) + tab1(29, 0) < 40 Then
        col = tab1(29, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) + tab1(20, 0) + tab1(21, 0) + tab1(22, 0) + tab1(23, 0) + tab1(24, 0) + tab1(25, 0) + tab1(26, 0) + tab1(27, 0) + tab1(28, 0) < 40 Then
        col = tab1(28, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) + tab1(20, 0) + tab1(21, 0) + tab1(22, 0) + tab1(23, 0) + tab1(24, 0) + tab1(25, 0) + tab1(26, 0) + tab1(27, 0) < 40 Then
        col = tab1(27, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) + tab1(20, 0) + tab1(21, 0) + tab1(22, 0) + tab1(23, 0) + tab1(24, 0) + tab1(25, 0) + tab1(26, 0) < 40 Then
        col = tab1(26, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) + tab1(20, 0) + tab1(21, 0) + tab1(22, 0) + tab1(23, 0) + tab1(24, 0) + tab1(25, 0) < 40 Then
        col = tab1(25, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) + tab1(20, 0) + tab1(21, 0) + tab1(22, 0) + tab1(23, 0) + tab1(24, 0) < 40 Then
        col = tab1(24, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) + tab1(20, 0) + tab1(21, 0) + tab1(22, 0) + tab1(23, 0) < 40 Then
        col = tab1(23, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) + tab1(20, 0) + tab1(21, 0) + tab1(22, 0) < 40 Then
        col = tab1(22, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) + tab1(20, 0) + tab1(21, 0) < 40 Then
        col = tab1(21, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) + tab1(20, 0) < 40 Then
        col = tab1(20, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) + tab1(19, 0) < 40 Then
        col = tab1(19, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) + tab1(18, 0) < 40 Then
        col = tab1(18, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) + tab1(17, 0) < 40 Then
        col = tab1(17, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) + tab1(16, 0) < 40 Then
        col = tab1(16, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) + tab1(15, 0) < 40 Then
        col = tab1(15, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) + tab1(14, 0) < 40 Then
        col = tab1(14, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) + tab1(13, 0) < 40 Then
        col = tab1(13, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) + tab1(12, 0) < 40 Then
        col = tab1(12, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) + tab1(11, 0) < 40 Then
        col = tab1(11, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) + tab1(10, 0) < 40 Then
        col = tab1(10, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) + tab1(9, 0) < 40 Then
        col = tab1(9, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) + tab1(8, 0) < 40 Then
        col = tab1(8, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) + tab1(7, 0) < 40 Then
        col = tab1(7, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) + tab1(6, 0) < 40 Then
        col = tab1(6, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) + tab1(5, 0) < 40 Then
        col = tab1(5, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) + tab1(4, 0) < 40 Then
        col = tab1(4, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) + tab1(3, 0) < 40 Then
        col = tab1(3, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) + tab1(2, 0) < 40 Then
        col = tab1(2, 1) - 1
        Cells(col, 9).Select
        ElseIf tab1(0, 0) + tab1(1, 0) < 40 Then
        col = tab1(1, 1) - 1
        End If
        col = tab1(0, 1)
        Cells(col, 9).Select
        Loop
        End Sub
    Si vous voulez un exemple de fichier excel je vous le donnerais.
    Ma macro se base sur un fichier ou des sous totaux on déja été fait et se base uniquement sur les sous totaux en question.
    Voila sauf que actuellement ma macro, ne donne pas le résultat que je veux par exemple si mes 4 première plage font moin de 40 lignes il doit inserer un saut de page . Sauf que la macro va jusqu'en bas du test et ne s'arrête pas sur le test validé .

  2. #2
    Expert confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2013
    Messages
    3 617
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Alimentation

    Informations forums :
    Inscription : Mai 2013
    Messages : 3 617
    Points : 5 912
    Points
    5 912
    Par défaut
    Bonjour,

    Un fichier au format xlsx pourrait servir. Mettre des données bidons si nécessaire...
    Y a-t-il des entêtes dans ton fichier qui pourraient servir de guide pour les sauts de pages ?
    Quel est ou quels sont les critères pour initier un saut de page ? Seulement les sous-totaux présents ?
    MPi²

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    technicien selection
    Inscrit en
    Novembre 2014
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Saône et Loire (Bourgogne)

    Informations professionnelles :
    Activité : technicien selection
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Novembre 2014
    Messages : 7
    Points : 1
    Points
    1
    Par défaut
    mise en forme fichier.xlsx
    enfet mon idée serai de recupérer l'adresse de la dernière cellule de la plage selectionné mettre mon saut de page ou sauvergarder la valeur du plot et supprimer les sous totaux.
    mon critère c'est que la plage face moin de 40 lignes soit une somme de sous totaux

    mes saut de pages se baseront sur le numéro de plot qui à normalement a chaque fois une valeur unique dans ce fichier

  4. #4
    Expert confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2013
    Messages
    3 617
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Alimentation

    Informations forums :
    Inscription : Mai 2013
    Messages : 3 617
    Points : 5 912
    Points
    5 912
    Par défaut
    Je ne suis pas certain que c'est ce que tu veux, mais tu pourrais faire un test et voir le résultat.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    Sub Pagination()
        Dim I As Long, nbLignes As Long, Idx As Long
        Dim Saut As Long        'stocke les sauts au fur et à mesure
        Dim Cnt As Long         'nombre de lignes dans une section
        Dim TabloSautLignes     'emmagasine les sauts de pages
     
        ReDim TabloSautLignes(0) 'initialise le tableau
     
        Sheets("Feuil1").Activate
        nbLignes = Cells(Rows.Count, "H").End(xlUp).Row
        ActiveSheet.PageSetup.PrintArea = "A6:L" & nbLignes
     
        'Déterminer les sauts de page et les mettre dans un tableau
        For I = 8 To nbLignes
            Cnt = Cnt + 1
            If InStr(1, Range("H" & I), "Nombre") > 0 Then
                'Si on dépasse 40 lignes, on utilise la valeur Saut (saut précédent)
                If Cnt > 40 Then
                    ReDim Preserve TabloSautLignes(Idx)
                    TabloSautLignes(Idx) = Saut
                    Idx = Idx + 1
                    I = Saut
                    Saut = 0
                    Cnt = 0
                Else
                    'Stocke le dernier saut possible
                    Saut = I
                End If
            End If
        Next
     
        'Mettre les sauts de pages compilés
        For I = 0 To UBound(TabloSautLignes)
            ActiveSheet.HPageBreaks.Add before:=Range("A" & TabloSautLignes(I) + 1)
        Next
     
    End Sub
    MPi²

  5. #5
    Nouveau Candidat au Club
    Homme Profil pro
    technicien selection
    Inscrit en
    Novembre 2014
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Saône et Loire (Bourgogne)

    Informations professionnelles :
    Activité : technicien selection
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Novembre 2014
    Messages : 7
    Points : 1
    Points
    1
    Par défaut
    Merci beaucoup on en est surement pas très loin
    c'est presque cela, néanmoins j'aimerai supprimer les sous totaux il ne sont donc pas inclus dans les 40 lignes à garder à la fin c'est pour cela que je voulais utilisé les sommes des sous totaux , stocker l'information du dernier plot ( collonne 1 de mon fichier) et faire mes sauts de page après avoir supprimer mes soustoaux

  6. #6
    Expert confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2013
    Messages
    3 617
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Alimentation

    Informations forums :
    Inscription : Mai 2013
    Messages : 3 617
    Points : 5 912
    Points
    5 912
    Par défaut
    Si je comprends bien, les sous-totaux ne sont plus nécessaires, donc on peut les éliminer.
    La valeur de ces totaux n'a pas besoin d'être affichée ou conservée non plus ?

    Et comme ceci ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    Sub Pagination()
        Dim I As Long, nbLignes As Long, Idx As Long
        Dim Saut As Long        'stocke les sauts au fur et à mesure
        Dim Cnt As Long         'nombre de lignes dans une section
        Dim TabloSautLignes     'emmagasine les sauts de pages
     
        ReDim TabloSautLignes(0) 'initialise le tableau
     
        Sheets("Feuil1").Activate
        nbLignes = Cells(Rows.Count, "H").End(xlUp).Row
        ActiveSheet.PageSetup.PrintArea = "A6:L" & nbLignes
     
        Range("A6:L" & nbLignes).RemoveSubtotal 'enlève les sous-totaux
     
        'Déterminer les sauts de page et les mettre dans un tableau
        For I = 8 To nbLignes
            Cnt = Cnt + 1
            If Range("I" & I) <> Range("I" & I + 1) Then
                'Si on dépasse 40 lignes, on utilise la valeur Saut (saut précédent)
                If Cnt > 40 Then
                    ReDim Preserve TabloSautLignes(Idx)
                    TabloSautLignes(Idx) = Saut
                    Idx = Idx + 1
                    I = Saut
                    Saut = 0
                    Cnt = 0
                Else
                    'Stocke le dernier saut possible
                    Saut = I
                End If
            End If
        Next
     
        'Mettre les sauts de pages compilés
        For I = 0 To UBound(TabloSautLignes)
            ActiveSheet.HPageBreaks.Add before:=Range("A" & TabloSautLignes(I) + 1)
        Next
     
    End Sub
    MPi²

  7. #7
    Nouveau Candidat au Club
    Homme Profil pro
    technicien selection
    Inscrit en
    Novembre 2014
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Saône et Loire (Bourgogne)

    Informations professionnelles :
    Activité : technicien selection
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Novembre 2014
    Messages : 7
    Points : 1
    Points
    1
    Par défaut
    Oui c'est parfait comme cela! j'ai juste une question dans ton code quand tu m'est :
    8 c'est mon nombre minimale de section? ou cela à rien avoir ? j'ai encore beaucoup de choses à apprendre sur le code mais c'est très instructif

    En tout cas merci de ton aide tu m'enlève une belle épine du pied et tu va me faire gagner des heures de travail ! Je reviendrai surement solicité le forum pour d'autre macro.

  8. #8
    Expert confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2013
    Messages
    3 617
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Alimentation

    Informations forums :
    Inscription : Mai 2013
    Messages : 3 617
    Points : 5 912
    Points
    5 912
    Par défaut
    8 est la ligne où je commence la boucle, c'est-à-dire que je pars de la ligne 8 et je descends en vérifiant si le code (Symbol) change.
    S'il change et qu'on n'a pas dépassé 40, je stockes le numéro de la ligne dans la variable Saut.
    Si on dépasse 40, je prends cette valeur (de Saut) que je mets dans un tableau.

    Lorsque cette boucle est terminée, je mets les sauts de pages à ces lignes stockées dans le tableau.
    MPi²

  9. #9
    Nouveau Candidat au Club
    Homme Profil pro
    technicien selection
    Inscrit en
    Novembre 2014
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Saône et Loire (Bourgogne)

    Informations professionnelles :
    Activité : technicien selection
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Novembre 2014
    Messages : 7
    Points : 1
    Points
    1
    Par défaut
    daccord parce il peut arriver que mon nombre minimale soit moins de 8 mais si j'insere une boite de dialogue qui défini cette valeur cela peu marché et le code pour quand même fonctionner?

  10. #10
    Expert confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2013
    Messages
    3 617
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Alimentation

    Informations forums :
    Inscription : Mai 2013
    Messages : 3 617
    Points : 5 912
    Points
    5 912
    Par défaut
    Oui, pas de problème.
    Par contre, mon code ne vérifie pas s'il y a des sections qui dépassent 40 lignes, ce qui n'était pas le cas dans ton fichier...
    MPi²

  11. #11
    Nouveau Candidat au Club
    Homme Profil pro
    technicien selection
    Inscrit en
    Novembre 2014
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Saône et Loire (Bourgogne)

    Informations professionnelles :
    Activité : technicien selection
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Novembre 2014
    Messages : 7
    Points : 1
    Points
    1
    Par défaut
    ah oui effectivement tu a raison.
    mais s'il dépasse les 40 lignes il ne pourra pas inserrer un saut de page à la fin de cette section?
    Le code est parfait je viens de le tester sur un fichier plus gros et ac toute ma macro de mise en forme tout s'imbrique parfaitement! c'est super

  12. #12
    Expert confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2013
    Messages
    3 617
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Alimentation

    Informations forums :
    Inscription : Mai 2013
    Messages : 3 617
    Points : 5 912
    Points
    5 912
    Par défaut
    Si tu penses que ça peut arriver qu'il y ait des sections de plus de 40 lignes, il faudrait modifier quelque peu la macro pour que ces sections soient coupées en plusieurs sections se terminant sur un changement de "Symbol". Il pourrait donc y avoir 40 lignes d'un "symbol" et soit 2 lignes (ou plus) pour la fin du symbol ou une série de lignes qui inclurait la fin du symbol et un ou d'autres symbol...

    Moins évident à écrire qu'à coder...
    MPi²

  13. #13
    Nouveau Candidat au Club
    Homme Profil pro
    technicien selection
    Inscrit en
    Novembre 2014
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Saône et Loire (Bourgogne)

    Informations professionnelles :
    Activité : technicien selection
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Novembre 2014
    Messages : 7
    Points : 1
    Points
    1
    Par défaut
    oui je pense comprendre ce qu'il faudrait faire, en gros il faudrai rajouté une condition supplémentaire à la macro
    oui c'est toujours compliqué d'expliqué ce genre de chose on s'y perd soit même!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. masque gaussien pour un tableau à une dimension
    Par bilzzbenzbilz dans le forum Traitement d'images
    Réponses: 1
    Dernier message: 20/02/2009, 15h04
  2. [FPDF] Tableau à une dimension contenant des valeurs
    Par kluck3000 dans le forum Bibliothèques et frameworks
    Réponses: 5
    Dernier message: 23/05/2008, 13h34
  3. Tri d'un tableau à une dimension
    Par Philippe PONS dans le forum VBA Access
    Réponses: 2
    Dernier message: 04/02/2008, 18h51
  4. Réponses: 4
    Dernier message: 17/01/2008, 17h06
  5. tableau à une dimension sans taille
    Par oscar.cesar dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 06/11/2007, 20h43

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo