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 :

Transformer Range en Cells [XL-2013]


Sujet :

Macros et VBA Excel

  1. #1
    Membre très actif
    Femme Profil pro
    Assistante
    Inscrit en
    Février 2016
    Messages
    166
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : Assistante

    Informations forums :
    Inscription : Février 2016
    Messages : 166
    Par défaut Transformer Range en Cells
    Bonjour,

    J'ai pu lire que pour améliorer la vitesse de transfert de valeurs d'un userform vers les cellules d'une feuille il fallait utiliser les Cells à la place des Range.
    J'aimerais bien tenter de le faire, car mon classeur est un peu lent.
    Mais je ne sais pas comment transformer ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    L = Sheets("Feuil1").Range("a10000").End(xlUp).Row + 1
    Range("A" & L).Value = UF1.Controls("Valider").Caption
    Quelqu'un peut-il m'aider svp ?

    Merci d'avance

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour,
    Quel en est l'intérêt?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Cells(L,"A").Value = UF1.Controls("Valider").Caption

  3. #3
    Expert confirmé

    Homme Profil pro
    Curieux
    Inscrit en
    Juillet 2012
    Messages
    5 169
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Curieux
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Juillet 2012
    Messages : 5 169
    Billets dans le blog
    5
    Par défaut
    Bonjour,

    personnellement, je n'ai jamais lu ou expérimenté une quelconque rapidité accrue en utilisant l'objet Cells() plutôt que l'objet Range(), mais on peut en apprendre tous les jours

    une petite variante pour écrire sur la première ligne non vide en partant du bas

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Cells(Rows.Count, 1).End(xlUp)(2).Value = UF1.Controls("Valider").Caption
    je préconise néanmoins de toujours indiquer la feuille hôte (voir le classeur hôte)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    With ThisWorkbook.Worksheets("MaFeuille")
        .Cells(.Rows.Count, 1).End(xlUp)(2).Value = UF1.Controls("Valider").Caption
    End With

  4. #4
    Expert confirmé
    Homme Profil pro
    aucune
    Inscrit en
    Avril 2016
    Messages
    7 563
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 84
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : aucune

    Informations forums :
    Inscription : Avril 2016
    Messages : 7 563
    Par défaut
    Bonjour
    J'ai pu lire que pour améliorer la vitesse de transfert de valeurs d'un userform vers les cellules d'une feuille il fallait utiliser les Cells à la place des Range.
    oui, mais pas comme tu l'utilises là, mais en spécifiant directement son dans la plage ******. Et tu ne gagneras ainsi que peu, et encore : sur une énorme plage et si cette plage est parfaitement rectangulaire et continue.

    EDIT : ***** au cours des cinq dernières années, je n'ai eu qu'un seul cas où il était plus judicieux d'utiliser cette numérotation interne des cellules Excel. Et encore ! je ne l'ai fait que pour "couper l'herbe sous les pieds" d'un forumeur hispanophone qui demandait du "tout-cuit" en prétendant que son application n'était pas destinée à d'autres que lui-même. En utilisant cette numérotation, non sur une plage de données, mais sur la totalité des cellules de la feuille de calcul, tout était ainsi construit pour capoter s'il passait de la version 2003 à la version 2007. Et cela n'a pas raté (et il est allé demander, sans l'obtenir, un secours sur un autre forum ...)

  5. #5
    Membre Expert
    Profil pro
    Inscrit en
    Février 2007
    Messages
    2 266
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 2 266
    Par défaut
    Bonjour à tous,

    Cells(x, y) ou même Cells(z) ne sont pas des Range ???
    eric

  6. #6
    Expert confirmé

    Homme Profil pro
    Curieux
    Inscrit en
    Juillet 2012
    Messages
    5 169
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Curieux
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Juillet 2012
    Messages : 5 169
    Billets dans le blog
    5
    Par défaut
    L’ambiguïté tient au fait que Range peut représenter deux choses :

    - l'objet Range : Range("A1")
    - la propriété Range de Worksheet, qui peut lui-même contenir des objets Range : Range(Range("A1"),Range("A2"))

    Et pour encore faire simple : Cells est un objet OU une propriété de l'objet Range

    J'espère ne pas avoir été trop lapidaire ou malavisé dans l'explication

  7. #7
    Membre Expert
    Profil pro
    Inscrit en
    Février 2007
    Messages
    2 266
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 2 266
    Par défaut
    Peut-être, mais j'ai du mal à voir pourquoi on ne le considérerait pas comme un objet Range (ce qu'annonce l'explorateur d'objets)
    Nom : 2017-10-07_13-38-33.png
Affichages : 1044
Taille : 26,1 Ko

  8. #8
    Expert confirmé
    Homme Profil pro
    aucune
    Inscrit en
    Avril 2016
    Messages
    7 563
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 84
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : aucune

    Informations forums :
    Inscription : Avril 2016
    Messages : 7 563
    Par défaut
    Bonjour eriiic
    Cells(x, y) ou même Cells(z) ne sont pas des Range ???
    ce sont bien évidemment des objets range.
    Mél3790 s'est tout simplement mal exprimé. Je pense qu'il voulait simplement dire "utiliser la notation cells plutôt que range pour spécifier un objet range".

  9. #9
    Membre Expert
    Profil pro
    Inscrit en
    Février 2007
    Messages
    2 266
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 2 266
    Par défaut
    Ok.
    J'ai testé par curiosité avec :
    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
    Sub test()
        Const nb   As Long = 50000
        Dim i As Long, t As Single
        Application.ScreenUpdating = False
        t = Timer
        For i = 1 To nb
            Range("A1").Value = nb
        Next i
    Debug.Print Timer - t
        t = Timer
        For i = 1 To nb
            Cells(1, 1).Value = nb
        Next i
    Debug.Print Timer - t
        t = Timer
        For i = 1 To nb
            Cells(1).Value = nb
        Next i
    Debug.Print Timer - t
    End Sub
    Résultat :
    Range("A1") : 82.05859
    Cells(1, 1) : 82.03906
    Cells(1) : 81.93359
    Effectivement il y a un gain qui doit être celui de l'interprétation mais bon, il faudrait des centaines de milliers d'écritures pour que ça se ressente.
    eric

  10. #10
    Membre très actif
    Femme Profil pro
    Assistante
    Inscrit en
    Février 2016
    Messages
    166
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : Assistante

    Informations forums :
    Inscription : Février 2016
    Messages : 166
    Par défaut
    Bonjour à tous,
    Merci pour vos échanges. Je ne suis pas certaines d'avoir tout compris, car je suis loin d'être une experte en VBA (et oui il y a un début à tout).

    En fait, mon formulaire est composé d'au moins 30 contrôles en tout genre (textbox, combobox, checkbox, etc ...). Une fois le formulaire complété, la personne click sur un bouton pour que toutes les valeurs des contrôles basculent dans les cellules d'un tableau d'une feuille. (de la colonne A à AJ)

    Le + 1 à la fin de "L = Sheets("Feuil1").Range("a10000").End(xlUp).Row + 1" c'est pour que en AJ il y ai un numéro unique qui vienne se créer grâce à ce code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Dim ID
     
    ID = Range("A1").Value
    ID = ID + 1
    Range("A1") = ID
    Range("Aj" & l).Value = ID
    Grâce au numéro qui se créé, je peux récupérer la ligne en cliquant dans une listbox par exemple.

    Le problème est que ça rame quand tout se bascule dans mon tableau, voir même faire planter mon classeur.
    C'est pour cela que j'aurais souhaité connaitre une astuce pour alléger mon code.

    J'ai essayé en supprimant le +1 à la fin de "L = Sheets("Feuil1").Range("a10000").End(xlUp).Row + 1", de ce fait je n'ai plus mon numéro unique qui s'inscrit à la fin de ma ligne, et du coup la transition est instantanée. Ce qui est parfait, mais mon numéro à la fin est indispensable ...

    Merci pour votre aide.

  11. #11
    Expert confirmé

    Homme Profil pro
    Curieux
    Inscrit en
    Juillet 2012
    Messages
    5 169
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Curieux
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Juillet 2012
    Messages : 5 169
    Billets dans le blog
    5
    Par défaut
    Bonjour,

    peux-tu publier l'intégralité de la procédure en question ?

  12. #12
    Membre très actif
    Femme Profil pro
    Assistante
    Inscrit en
    Février 2016
    Messages
    166
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : Assistante

    Informations forums :
    Inscription : Février 2016
    Messages : 166
    Par défaut
    Voici ma fonction :

    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
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    Function cb1forfait()
     
    Application.ScreenUpdating = False
     
    With ThisWorkbook.Worksheets("Feuil1")
     
    l = Sheets("Feuil1").Range("a10000").End(xlUp).Row '+ 1
     
    Range("A" & l).Value = UFforfait1.Controls("Valider").Caption
    Range("B" & l).Value = UFforfait1.Controls("cb1")
    Range("C" & l).Value = UFforfait1.Controls("cat")
    Range("D" & l).Value = UFforfait1.Controls("TextBox7").Value
    Range("E" & l).Value = UFforfait1.Controls("TextBox145")
    Range("I" & l).Value = UFforfait1.Controls("ComboBox13") 
    Range("F" & l).Value = UFProgrammationForfait.Controls("cbformation1")
    Range("G" & l).Value = UFProgrammationForfait.Controls("TBintituléNANTES1")
    Range("H" & l).Value = UFProgrammationForfait.Controls("T131") & " au " & UFProgrammationForfait.Controls("T141")
    Range("AG" & l).Value = CDate(UFProgrammationForfait.Controls("T131"))
    Range("AH" & l).Value = CDate(UFProgrammationForfait.Controls("T141"))
    Range("J" & l).Value = UFProgrammationForfait.Controls("Cbsemaine1").Value 
    Range("K" & l).Value = Round(Val(UFProgrammationForfait.Controls("T41").Value), 2)
    Range("L" & l).Value = Round(Val(UFProgrammationForfait.Controls("T51").Value), 2)
    Range("M" & l).Value = UFProgrammationForfait.Controls("T61")
    Range("N" & l).Value = UFProgrammationForfait.Controls("T71")
    Range("O" & l).Value = UFProgrammationForfait.Controls("Cborganisme1")
    Range("P" & l).Value = UFProgrammationForfait.Controls("Cblieu1")
    Range("Q" & l).Value = Round(Val(UFProgrammationForfait.Controls("T91").Value), 2) 
    Range("R" & l).Value = Round(Val(UFforfait1.Controls("T101").Value), 2) 
    Range("S" & l).Value = Round(Val(UFforfait1.Controls("T111").Value), 2) 
    Range("T" & l).Value = Round(Val(UFforfait1.Controls("T121").Value), 2) 
    Range("Y" & l).Value = UFProgrammationForfait.Controls("Cdm1").Value 
     
    ' 
    Range("AA" & l).Value = UFProgrammationForfait.Controls("TextBox6666").Value
    Range("AB" & l).Value = UFProgrammationForfait.Controls("TextBox1111").Value
    Range("AC" & l).Value = UFProgrammationForfait.Controls("TextBox2222").Value
    Range("AD" & l).Value = UFProgrammationForfait.Controls("TextBox3333").Value
    Range("AE" & l).Value = UFProgrammationForfait.Controls("TextBox4444").Value
    Range("AF" & l).Value = UFProgrammationForfait.Controls("TextBox5555").Value
     
                            If UFforfait1.Controls("CheckBox1").Value = True Then 
                               Range("x" & l).Value = "ok"
     
                            End If
                            If UFforfait1.Controls("CheckBox2").Value = True Then 
                                Range("z" & l).Value = "ok"
                            End If
     
    If UFforfait1.Controls("CheckBox1").Value = True And UFforfait1.Controls("CheckBox2").Value = True Then
                                '--------------------------------------
                            Range("A" & l).Interior.ColorIndex = 45
                            Range("B" & l).Interior.ColorIndex = 45
                            Range("C" & l).Interior.ColorIndex = 45
                            Range("D" & l).Interior.ColorIndex = 45
                            Range("E" & l).Interior.ColorIndex = 45
                            Range("I" & l).Interior.ColorIndex = 45
                            Range("F" & l).Interior.ColorIndex = 45
                            Range("G" & l).Interior.ColorIndex = 45
                            Range("H" & l).Interior.ColorIndex = 45
                            Range("AG" & l).Interior.ColorIndex = 45
                            Range("AH" & l).Interior.ColorIndex = 45
                            Range("J" & l).Interior.ColorIndex = 45
                            Range("K" & l).Interior.ColorIndex = 45
                            Range("L" & l).Interior.ColorIndex = 45
                            Range("M" & l).Interior.ColorIndex = 45
                            Range("N" & l).Interior.ColorIndex = 45
                            Range("O" & l).Interior.ColorIndex = 45
                            Range("P" & l).Interior.ColorIndex = 45
                            Range("Q" & l).Interior.ColorIndex = 45
                            Range("R" & l).Interior.ColorIndex = 45
                            Range("S" & l).Interior.ColorIndex = 45
                            Range("T" & l).Interior.ColorIndex = 45
                            Range("U" & l).Interior.ColorIndex = 45
                            Range("V" & l).Interior.ColorIndex = 45
                            Range("W" & l).Interior.ColorIndex = 45
                             Range("AJ" & l).Interior.ColorIndex = 45
                             Range("x" & l).Interior.ColorIndex = 45
                             Range("y" & l).Interior.ColorIndex = 45
                             Range("z" & l).Interior.ColorIndex = 45
                             Range("ai" & l).Interior.ColorIndex = 45
     
                            ' POUR POINTAGES
                            Range("AA" & l).Interior.ColorIndex = 45
                            Range("AB" & l).Interior.ColorIndex = 45
                            Range("AC" & l).Interior.ColorIndex = 45
                            Range("AD" & l).Interior.ColorIndex = 45
                            Range("AE" & l).Interior.ColorIndex = 45
                            Range("AF" & l).Interior.ColorIndex = 45
     
    ElseIf UFforfait1.Controls("CheckBox1").Value = True And UFforfait1.Controls("CheckBox2").Value = False Then
                                '--------------------------------------
                            Range("A" & l).Interior.ColorIndex = 38
                            Range("B" & l).Interior.ColorIndex = 38
                            Range("C" & l).Interior.ColorIndex = 38
                            Range("D" & l).Interior.ColorIndex = 38
                            Range("E" & l).Interior.ColorIndex = 38
                            Range("I" & l).Interior.ColorIndex = 38
                            Range("F" & l).Interior.ColorIndex = 38
                            Range("G" & l).Interior.ColorIndex = 38
                            Range("H" & l).Interior.ColorIndex = 38
                            Range("AG" & l).Interior.ColorIndex = 38
                            Range("AH" & l).Interior.ColorIndex = 38
                            Range("J" & l).Interior.ColorIndex = 38
                            Range("K" & l).Interior.ColorIndex = 38
                            Range("L" & l).Interior.ColorIndex = 38
                            Range("M" & l).Interior.ColorIndex = 38
                            Range("N" & l).Interior.ColorIndex = 38
                            Range("O" & l).Interior.ColorIndex = 38
                            Range("P" & l).Interior.ColorIndex = 38
                            Range("Q" & l).Interior.ColorIndex = 38
                            Range("R" & l).Interior.ColorIndex = 38
                            Range("S" & l).Interior.ColorIndex = 38
                            Range("T" & l).Interior.ColorIndex = 38
                            Range("U" & l).Interior.ColorIndex = 38
                            Range("V" & l).Interior.ColorIndex = 38
                            Range("W" & l).Interior.ColorIndex = 38
                            Range("AJ" & l).Interior.ColorIndex = 38
                            Range("x" & l).Interior.ColorIndex = 38
                             Range("y" & l).Interior.ColorIndex = 38
                             Range("z" & l).Interior.ColorIndex = 38
                             Range("ai" & l).Interior.ColorIndex = 38
     
     
                            Range("AA" & l).Interior.ColorIndex = 38
                            Range("AB" & l).Interior.ColorIndex = 38
                            Range("AC" & l).Interior.ColorIndex = 38
                            Range("AD" & l).Interior.ColorIndex = 38
                            Range("AE" & l).Interior.ColorIndex = 38
                            Range("AF" & l).Interior.ColorIndex = 38
     
                                '--------------------------------------
     
    ElseIf UFforfait1.Controls("CheckBox1").Value = False And UFforfait1.Controls("CheckBox2").Value = True Then
     
                            Range("A" & l).Interior.ColorIndex = 45
                            Range("B" & l).Interior.ColorIndex = 45
                            Range("C" & l).Interior.ColorIndex = 45
                            Range("D" & l).Interior.ColorIndex = 45
                            Range("E" & l).Interior.ColorIndex = 45
                            Range("I" & l).Interior.ColorIndex = 45
                            Range("F" & l).Interior.ColorIndex = 45
                            Range("G" & l).Interior.ColorIndex = 45
                            Range("H" & l).Interior.ColorIndex = 45
                            Range("AG" & l).Interior.ColorIndex = 45
                            Range("AH" & l).Interior.ColorIndex = 45
                            Range("J" & l).Interior.ColorIndex = 45
                            Range("K" & l).Interior.ColorIndex = 45
                            Range("L" & l).Interior.ColorIndex = 45
                            Range("M" & l).Interior.ColorIndex = 45
                            Range("N" & l).Interior.ColorIndex = 45
                            Range("O" & l).Interior.ColorIndex = 45
                            Range("P" & l).Interior.ColorIndex = 45
                            Range("Q" & l).Interior.ColorIndex = 45
                            Range("R" & l).Interior.ColorIndex = 45
                            Range("S" & l).Interior.ColorIndex = 45
                            Range("T" & l).Interior.ColorIndex = 45
                            Range("U" & l).Interior.ColorIndex = 45
                            Range("V" & l).Interior.ColorIndex = 45
                            Range("W" & l).Interior.ColorIndex = 45
                            Range("AJ" & l).Interior.ColorIndex = 45
                            Range("x" & l).Interior.ColorIndex = 45
                             Range("y" & l).Interior.ColorIndex = 45
                             Range("z" & l).Interior.ColorIndex = 45
                             Range("ai" & l).Interior.ColorIndex = 45
                            ' POUR POINTAGES
                            Range("AA" & l).Interior.ColorIndex = 45
                            Range("AB" & l).Interior.ColorIndex = 45
                            Range("AC" & l).Interior.ColorIndex = 45
                            Range("AD" & l).Interior.ColorIndex = 45
                            Range("AE" & l).Interior.ColorIndex = 45
                            Range("AF" & l).Interior.ColorIndex = 45
     
                                '--------------------------------------
    ElseIf UFforfait1.Controls("CheckBox1").Value = False And UFforfait1.Controls("CheckBox2").Value = False Then
     
                            Range("A" & l).Interior.ColorIndex = xlNone
                            Range("B" & l).Interior.ColorIndex = xlNone
                            Range("C" & l).Interior.ColorIndex = xlNone
                            Range("D" & l).Interior.ColorIndex = xlNone
                            Range("E" & l).Interior.ColorIndex = xlNone
                            Range("I" & l).Interior.ColorIndex = xlNone
                            Range("F" & l).Interior.ColorIndex = xlNone
                            Range("G" & l).Interior.ColorIndex = xlNone
                            Range("H" & l).Interior.ColorIndex = xlNone
                            Range("AG" & l).Interior.ColorIndex = xlNone
                            Range("AH" & l).Interior.ColorIndex = xlNone
                            Range("J" & l).Interior.ColorIndex = xlNone
                            Range("K" & l).Interior.ColorIndex = xlNone
                            Range("L" & l).Interior.ColorIndex = xlNone
                            Range("M" & l).Interior.ColorIndex = xlNone
                            Range("N" & l).Interior.ColorIndex = xlNone
                            Range("O" & l).Interior.ColorIndex = xlNone
                            Range("P" & l).Interior.ColorIndex = xlNone
                            Range("Q" & l).Interior.ColorIndex = xlNone
                            Range("R" & l).Interior.ColorIndex = xlNone
                            Range("S" & l).Interior.ColorIndex = xlNone
                            Range("T" & l).Interior.ColorIndex = xlNone
                            Range("U" & l).Interior.ColorIndex = xlNone
                            Range("V" & l).Interior.ColorIndex = xlNone
                            Range("W" & l).Interior.ColorIndex = xlNone
                             Range("AJ" & l).Interior.ColorIndex = xlNone
                             Range("x" & l).Interior.ColorIndex = xlNone
                             Range("y" & l).Interior.ColorIndex = xlNone
                             Range("z" & l).Interior.ColorIndex = xlNone
                             Range("ai" & l).Interior.ColorIndex = xlNone
     
                            Range("AA" & l).Interior.ColorIndex = xlNone
                            Range("AB" & l).Interior.ColorIndex = xlNone
                            Range("AC" & l).Interior.ColorIndex = xlNone
                            Range("AD" & l).Interior.ColorIndex = xlNone
                            Range("AE" & l).Interior.ColorIndex = xlNone
                            Range("AF" & l).Interior.ColorIndex = xlNone
     
                                '--------------------------------------
     
    End If
     
    'Ajoute un numéro d'index unique en bout de ligne :
    Dim ID
     
    ID = Range("A1").Value
    ID = ID + 1
    Range("A1") = ID
    Range("Aj" & l).Value = ID
    'End If
     
    End With
     
    Application.ScreenUpdating = True
     
    End Function
     
    Private Sub Valider_Click()
     
    Application.ScreenUpdating = False
     
    Call cb1forfait
     
    MsgBox "Enregistrement terminé !", vbInformation, "Actualisation"
     
    Application.ScreenUpdating = True
     
    End Sub

  13. #13
    Invité
    Invité(e)
    Par défaut
    Bonjour,
    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
    Function cb1forfait()
        Application.ScreenUpdating = False: Application.EnableEvents=False
        With ThisWorkbook.Worksheets("Feuil1")
            l = Sheets("Feuil1").Range("a10000").End(xlUp).Row '+ 1
            Range("A" & l).Value = UFforfait1.Controls("Valider").Caption
            Range("B" & l).Value = UFforfait1.Controls("cb1")
            Range("C" & l).Value = UFforfait1.Controls("cat")
            Range("D" & l).Value = UFforfait1.Controls("TextBox7").Value
            Range("E" & l).Value = UFforfait1.Controls("TextBox145")
            Range("I" & l).Value = UFforfait1.Controls("ComboBox13")
            Range("F" & l).Value = UFProgrammationForfait.Controls("cbformation1")
            Range("G" & l).Value = UFProgrammationForfait.Controls("TBintituléNANTES1")
            Range("H" & l).Value = UFProgrammationForfait.Controls("T131") & " au " & UFProgrammationForfait.Controls("T141")
            Range("AG" & l).Value = CDate(UFProgrammationForfait.Controls("T131"))
            Range("AH" & l).Value = CDate(UFProgrammationForfait.Controls("T141"))
            Range("J" & l).Value = UFProgrammationForfait.Controls("Cbsemaine1").Value
            Range("K" & l).Value = Round(Val(UFProgrammationForfait.Controls("T41").Value), 2)
            Range("L" & l).Value = Round(Val(UFProgrammationForfait.Controls("T51").Value), 2)
            Range("M" & l).Value = UFProgrammationForfait.Controls("T61")
            Range("N" & l).Value = UFProgrammationForfait.Controls("T71")
            Range("O" & l).Value = UFProgrammationForfait.Controls("Cborganisme1")
            Range("P" & l).Value = UFProgrammationForfait.Controls("Cblieu1")
            Range("Q" & l).Value = Round(Val(UFProgrammationForfait.Controls("T91").Value), 2)
            Range("R" & l).Value = Round(Val(UFforfait1.Controls("T101").Value), 2)
            Range("S" & l).Value = Round(Val(UFforfait1.Controls("T111").Value), 2)
            Range("T" & l).Value = Round(Val(UFforfait1.Controls("T121").Value), 2)
            Range("Y" & l).Value = UFProgrammationForfait.Controls("Cdm1").Value
            Range("AA" & l).Value = UFProgrammationForfait.Controls("TextBox6666").Value
            Range("AB" & l).Value = UFProgrammationForfait.Controls("TextBox1111").Value
            Range("AC" & l).Value = UFProgrammationForfait.Controls("TextBox2222").Value
            Range("AD" & l).Value = UFProgrammationForfait.Controls("TextBox3333").Value
            Range("AE" & l).Value = UFProgrammationForfait.Controls("TextBox4444").Value
            Range("AF" & l).Value = UFProgrammationForfait.Controls("TextBox5555").Value
            Select Case CStr(Abs(UFforfait1.Controls("CheckBox1").Value)) & CStr(Abs(UFforfait1.Controls("CheckBox2").Value))
                Case "00"
                    Range(Range("A" & l), Range("AJ" & l)).Interior.ColorIndex = xlNone
                Case "01"
                    Range(Range("A" & l), Range("AJ" & l)).Interior.ColorIndex = 45
                    Range("Z" & l).Value = "ko"
                Case "10"
                    Range(Range("A" & l), Range("AJ" & l)).Interior.ColorIndex = 38
                    Range("x" & l).Value = "ok"
                Case "11"
                    Range(Range("A" & l), Range("AJ" & l)).Interior.ColorIndex = 45
                    Range("x" & l).Value = "ok"
                    Range("Z" & l).Value = "ko"
            End Select
            Dim ID 'Ajoute un numéro d'index unique en bout de ligne :
            ID = Range("A1").Value: ID = ID + 1: Range("A1") = ID: Range("Aj" & l).Value = ID
        End With
        Application.ScreenUpdating = True: Application.EnableEvents=true
    End Function
    Dernière modification par Invité ; 10/10/2017 à 11h22.

  14. #14
    Membre très actif
    Femme Profil pro
    Assistante
    Inscrit en
    Février 2016
    Messages
    166
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : Assistante

    Informations forums :
    Inscription : Février 2016
    Messages : 166
    Par défaut
    Bonjour à tous,

    dysorthographie ton code fonctionne très bien, par contre, il n'ajoute pas une ligne à la fin du tableau, mais écrase la dernière ligne remplie

  15. #15
    Expert confirmé
    Homme Profil pro
    aucune
    Inscrit en
    Avril 2016
    Messages
    7 563
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 84
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : aucune

    Informations forums :
    Inscription : Avril 2016
    Messages : 7 563
    Par défaut
    Décommente alors le + 1 dans
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    l = Sheets("Feuil1").Range("a10000").End(xlUp).Row '+ 1
    Ta réaction met en évidence que tu ne sais que copier/coller, sans analyser, sans comprendre ...

  16. #16
    Membre très actif
    Femme Profil pro
    Assistante
    Inscrit en
    Février 2016
    Messages
    166
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : Assistante

    Informations forums :
    Inscription : Février 2016
    Messages : 166
    Par défaut
    J'ai bien décommenté le +1 avant de voir ta réponse, seulement, j'ai toujours ce problème de lenteur, ça rame, à cause de ça.
    Donc mon problème reste le même malheureusement.
    Je ne sais pas comment formuler le +1 autrement, à moins qu'il n'y ai pas d'autres solution ..

  17. #17
    Expert éminent
    Avatar de Marc-L
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2013
    Messages
    9 468
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2013
    Messages : 9 468
    Par défaut
    Bonjour, bonjour !

    Un calcul +1 étant instantané, cela ne peut donc pas ramer à cause de ça !

    Si chez un garagiste on affirme « ma boîte de vitesse est morte » alors ne pas s'étonner de son remplacement
    même si en fait il n'y avait qu'un boulon à resserrer !

    Exporter les modules, les supprimer, sauvegarder puis les réimporter, sait-on jamais …
    Ou encore les importer dans un nouveau classeur et comparer.

    Si Excel est utilisé comme base de données, ne pas s'étonner de sa lenteur car ce n'est pas sa fonction ! Access oui …

    Voilà, voilà !

    ___________________________________________________________________________________________________________
    Je suis Paris, Barcelone, London, Manchester, Egypte, Stockholm, Istanbul, Berlin, Nice, Bruxelles, Charlie, …

  18. #18
    Membre très actif
    Femme Profil pro
    Assistante
    Inscrit en
    Février 2016
    Messages
    166
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : Assistante

    Informations forums :
    Inscription : Février 2016
    Messages : 166
    Par défaut
    Bonjour,

    Tu m'as mis sur une piste.
    C'est vrai qu'il n'est pas normal que cela rame.
    Du coup, j'ai tenté autre chose, tout en gardant le code de Dysorthographie.

    Mes données se basculent dans un tableau. Tableau que je viens de convertir en plage.
    Je réessaye de basculer mes valeurs, et là pouf ! C'est instantané ! Génial.

    Donc je présume que c'est la mise en forme du tableau à chaque ajout de ligne qui fait ramé mon fichier.

    Ce qui m'ennui, car l'utilisation d'un tableau est préférable par rapport à mon projet :s

  19. #19
    Rédacteur
    Avatar de Philippe Tulliez
    Homme Profil pro
    Formateur, développeur et consultant Excel, Access, Word et VBA
    Inscrit en
    Janvier 2010
    Messages
    13 173
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Formateur, développeur et consultant Excel, Access, Word et VBA

    Informations forums :
    Inscription : Janvier 2010
    Messages : 13 173
    Billets dans le blog
    53
    Par défaut
    Bonjour Robert,
    Dans ta fonction nommée cb1forfait que tu as proposée dans le fil #13 et sauf erreur de ma part, il me semble qu'il y a des erreurs aux lignes 5 à 33 tout au moins si les objets Range ont comme objet parent ThisWorkbook.Worksheets("Feuil1"). Il manque le point devant Range.
    Il me semble qu'aux lignes suivantes le problème est le même.
    Philippe Tulliez
    Ce que l'on conçoit bien s'énonce clairement, et les mots pour le dire arrivent aisément. (Nicolas Boileau)
    Lorsque vous avez la réponse à votre question, n'oubliez pas de cliquer sur et si celle-ci est pertinente pensez à voter
    Mes tutoriels : Utilisation de l'assistant « Insertion de fonction », Les filtres avancés ou élaborés dans Excel
    Mon dernier billet : Utilisation de la fonction Dir en VBA pour vérifier l'existence d'un fichier

  20. #20
    Invité
    Invité(e)
    Par défaut
    Bonjour Philippe,
    oui tu as raison, l'erreur provient du fait que j'ai repris le code initial tel quel pour le simplifier!

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

Discussions similaires

  1. Différence entre Range et cells
    Par bibvba dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 19/06/2017, 12h36
  2. Plage de données : Range vs Cells : Erreur 1004
    Par Secco dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 10/06/2008, 17h29
  3. Convertir Range en Cells
    Par Sakapatate dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 03/05/2008, 14h18
  4. Définition d'un range par Cells(), Cells()
    Par Dereck07 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 04/03/2008, 22h11
  5. Export Excel - Souci avec Range et Cells
    Par timoth dans le forum VBA Access
    Réponses: 3
    Dernier message: 14/02/2008, 15h00

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