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 :

Ajout d'un code en fonction d'une demande [XL-2013]


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre régulier
    Homme Profil pro
    Technicien en Automatisme
    Inscrit en
    Novembre 2015
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Technicien en Automatisme

    Informations forums :
    Inscription : Novembre 2015
    Messages : 7
    Par défaut Ajout d'un code en fonction d'une demande
    Bonjour,

    J'ai une soucis sur ma synchronisation dans mon tableau, je m'explique :

    Lorsque je fait m'a demande dans Lot Elec - APS - Repérage sur site je devrais avoir le code XHRSNom : Capture excel developpez.PNG
Affichages : 291
Taille : 25,1 Ko

    Or lors de l'execution de mon Userform, lorsque j'ajoute ceci dans ma feuil1

    Il m'affiche

    Nom : Capture excel developpez 1.PNG
Affichages : 242
Taille : 14,7 Ko

    je vous joins le code que j'ai fais :

    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
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    Dim f
     
    Private Sub b_exit_usf6_Click()
       Unload UserForm1 'masque aussi userform1
    End Sub
     
     
     
    Private Sub UserForm_Initialize()
      Set f = Sheets("BD")
      Set mondico = CreateObject("Scripting.Dictionary")
      For Each C In Range(f.[A2], f.[A65000].End(xlUp))
        mondico(C.Value) = C.Value
      Next C
      Me.ListBox1.List = mondico.items
      Me.ListBox1.MultiSelect = fmMultiSelectMulti
    End Sub
    Private Sub ListBox1_Change()
        Me.ListBox3.Clear
        Set mondico = CreateObject("Scripting.Dictionary")
        For Each C In Range(f.[A2], f.[C65000].End(xlUp))
            For k = 0 To Me.ListBox1.ListCount - 1
              If Me.ListBox1.Selected(k) = True Then
                If C = Me.ListBox1.List(k, 0) Then
                  temp = C.Offset(, 1)
                  mondico(temp) = temp
                End If
              End If
            Next k
        Next C
        Me.ListBox2.List = mondico.items
    End Sub
    Private Sub ListBox2_Change()
      Me.ListBox3.Clear
      For Each C In Range(f.[B2], f.[B65000].End(xlUp))
        For k = 0 To Me.ListBox2.ListCount - 1
          If Me.ListBox2.Selected(k) = True Then
            If C = Me.ListBox2.List(k, 0) Then Me.ListBox3.AddItem C.Offset(, 1)
          End If
         Next k
      Next C
    End Sub
    Private Sub CommandButton1_Click()
    Dim I As Integer, y As Integer
     
    'Dim Cel As Range
    'Set Cel = Sh.[B:B].Find("*", , , , xlByRows, xlPrevious)
    'If Cel Is Nothing Then Exit Sub
    'y = Cel.Row
     
        Set sh = Sheets("Feuil1")
        y = sh.[B:B].Find("*", , , , xlByRows, xlPrevious).Row
     
     
        With Me.ListBox1
            For I = 0 To .ListCount - 1
            If .Selected(I) = True Then
                y = y + 1
        sh.Range("B" & y).Value = .List(I)
     '   With sh.Range("A" & y & ":G" & y).Interior
     '       .Pattern = xlSolid
     '      .ThemeColor = xlThemeColorAccent6
     '       .TintAndShade = 0.799981688894314
    '          .Color = 10066431
     
       '    End With
                With sh.Range("B" & y).Font
                .Name = "Calibri"
                .Size = 9
                .Bold = True
                .ThemeColor = xlThemeColorLight2
                .TintAndShade = 0
    End With
    End If
    Next I
     
     
     
     
     
        With Me.ListBox2
            For I = 0 To .ListCount - 1
            If .Selected(I) = True Then
            y = y + 1
            sh.Range("B" & y).Value = .List(I)
            With sh.Range("B" & y).Font
                .Name = "Calibri"
                .Size = 9
                .Bold = True
                .ThemeColor = xlThemeColorLight2
                .TintAndShade = 0
            End With
            End If
            Next I
        End With
     
        With Me.ListBox3
            For I = 0 To .ListCount - 1
            If .Selected(I) = True Then
            y = y + 1
            sh.Range("B" & y).Value = .List(I)
            With sh.Range("B" & y).Font
                .Name = "Calibri"
                .FontStyle = "Normal"
                .Size = 9
                .ThemeColor = xlThemeColorAccent1
                .TintAndShade = -0.249977111117893
            End With
            End If
        Next I
        End With
     
     
     With Application
            .ScreenUpdating = False
            .DisplayStatusBar = False
            .Calculation = xlCalculationManual
    End With
     
    Range("G12").Formula = "=VLOOKUP(B12,tableau3,2)"
    Range("C12:G12").HorizontalAlignment = xlCenter
    Range("C12:G12").VerticalAlignment = xlCenter
    Range("G12").AutoFill Range("G12:G" & Range("B65536").End(xlUp).Row)
     
    Range("F12").Formula = "=SUM(RC[-2]*RC[-1])"
    Range("F12").AutoFill Range("F12:F" & Range("B65536").End(xlUp).Row)
    Range("D12") = 7.5
     
    Range("D12").AutoFill Range("D12:D" & Range("B65536").End(xlUp).Row)
    Range("C12") = "h"
    Range("C12").AutoFill Range("C12:C" & Range("B65536").End(xlUp).Row)
     
    With Application
            .Calculation = xlCalculationAutomatic
            .DisplayStatusBar = True
            .CutCopyMode = False
            .ScreenUpdating = True
    End With
     
     
      For I = 0 To Me.ListBox1.ListCount - 1
      Me.ListBox1.Selected(I) = False
      Next I
      For I = 0 To Me.ListBox2.ListCount - 1
      Me.ListBox2.RemoveItem 0
      Next I
      For I = 0 To Me.ListBox3.ListCount - 1
      Me.ListBox3.RemoveItem 0
      Next I
      Me.ListBox1.SetFocus
    End With
     
        Range("E12:G300").Select
        With Selection.Font
            .Name = "Calibri"
            .Size = 9
    '       .Strikethrough = False
    '       .Superscript = False
    '        .Subscript = False
    '        .OutlineFont = False
    '        .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .ThemeFont = xlThemeFontMinor
        End With
        Selection.Font.Bold = True
        Range("D12:D42").Select
        With Selection.Font
            .Name = "Calibri"
            .Size = 9
    '        .Strikethrough = False
    '        .Superscript = False
    '        .Subscript = False
    '        .OutlineFont = False
    '        .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .ThemeFont = xlThemeFontMinor
        End With
        Range("C12:C43").Select
        With Selection.Font
        With Selection.Font
            .Name = "Calibri"
            .Size = 9
    '        .Strikethrough = False
    '        .Superscript = False
    '        .Subscript = False
    '        .OutlineFont = False
    '        .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .ThemeFont = xlThemeFontMinor
        End With
        With Selection.Font
            .ThemeColor = xlThemeColorAccent2
            .TintAndShade = -0.249977111117893
        End With
        End With
        Range("A1").Select
    End Sub
    Private Sub CommandButton2_Click()
     
    Dim I As Integer, y As Integer
        Set sh = Sheets("Feuil1")
        y = sh.[B:B].Find("*", , , , xlByRows, xlPrevious).Row
     
           With Me.ListBox2
            For I = 0 To .ListCount - 1
            If .Selected(I) = True Then
            y = y
     
         End If
            Next I
        End With
     
        With Me.ListBox3
            For I = 0 To .ListCount - 1
            If .Selected(I) = True Then
            y = y + 1
            sh.Range("B" & y).Value = .List(I)
            With sh.Range("B" & y).Font
                .Name = "Calibri"
                .FontStyle = "Normal"
                .Size = 9
                .ThemeColor = xlThemeColorAccent1
                .TintAndShade = -0.249977111117893
            End With
            End If
        Next I
        End With
     
     
     
     
     
     
    Range("G12").Formula = "=VLOOKUP(B12,tableau3,2)"
    Range("C12:G12").HorizontalAlignment = xlCenter
    Range("C12:G12").VerticalAlignment = xlCenter
    Range("G12").AutoFill Range("G12:G" & Range("B65536").End(xlUp).Row)
    Range("F12").Formula = "=SUM(RC[-2]*RC[-1])"
    Range("F12").AutoFill Range("F12:F" & Range("B65536").End(xlUp).Row)
    Range("D12") = 7.5
    Range("D12").AutoFill Range("D12:D" & Range("B65536").End(xlUp).Row)
    Range("C12") = "h"
    Range("C12").AutoFill Range("C12:C" & Range("B65536").End(xlUp).Row)
     
     
    End Sub
     
    Private Sub CommandButton6_Click()
    Dim I As Integer, y As Integer
        Set sh = Sheets("Feuil1")
        y = sh.[B:B].Find("*", , , , xlByRows, xlPrevious).Row
     
           With Me.ListBox2
            For I = 0 To .ListCount - 1
            If .Selected(I) = True Then
            y = y + 1
            sh.Range("B" & y).Value = .List(I)
            With sh.Range("B" & y).Font
                .Name = "Calibri"
                .Size = 9
                .Bold = True
                .ThemeColor = xlThemeColorLight2
                .TintAndShade = 0
            End With
         End If
            Next I
        End With
     
        With Me.ListBox3
            For I = 0 To .ListCount - 1
            If .Selected(I) = True Then
            y = y + 1
            sh.Range("B" & y).Value = .List(I)
            With sh.Range("B" & y).Font
                .Name = "Calibri"
                .FontStyle = "Normal"
                .Size = 9
                .ThemeColor = xlThemeColorAccent1
                .TintAndShade = -0.249977111117893
            End With
            End If
        Next I
        End With
     
     
     
     
     
     
    Range("G12").Formula = "=VLOOKUP(B12,tableau3,2)"
    Range("C12:G12").HorizontalAlignment = xlCenter
    Range("C12:G12").VerticalAlignment = xlCenter
    Range("G12").AutoFill Range("G12:G" & Range("B65536").End(xlUp).Row)
    Range("F12").Formula = "=SUM(RC[-2]*RC[-1])"
    Range("F12").AutoFill Range("F12:F" & Range("B65536").End(xlUp).Row)
    Range("D12") = 7.5
    Range("D12").AutoFill Range("D12:D" & Range("B65536").End(xlUp).Row)
    Range("C12") = "h"
    Range("C12").AutoFill Range("C12:C" & Range("B65536").End(xlUp).Row)
    End Sub

    JE vous remercie d'avance pour votre aide .

    si je me suis mal expliqué dans m'a démarche dit moi j'essayerais de mieux expliquer

    Cordialement

  2. #2
    Expert confirmé
    Homme Profil pro
    aucune
    Inscrit en
    Septembre 2011
    Messages
    8 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : aucune

    Informations forums :
    Inscription : Septembre 2011
    Messages : 8 208
    Par défaut
    Bonjour,

    Tu as fait un louable effort pour expliquer sans joindre d'entrée le classeur. Bravo. Maintenant, comme le problème vient peut-être de la disposition de tes données, il serait souhaitable que tu le mettes en pièce jointe.

  3. #3
    Membre régulier
    Homme Profil pro
    Technicien en Automatisme
    Inscrit en
    Novembre 2015
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Technicien en Automatisme

    Informations forums :
    Inscription : Novembre 2015
    Messages : 7
    Par défaut
    Alors pour mieux m'expliquer...

    J'ai ma base de donnée
    Nom : Capture excel developpez 2.PNG
Affichages : 230
Taille : 54,2 Ko

    ensuite j'ai ma feuille avec mon userform qui me permet de choisir se que je veux ajouter mais voilà il me sélectionne pas le bon code ce qui me donne ceci

    Nom : Capture excel developpez 3.PNG
Affichages : 272
Taille : 56,2 Ko

    je joins le fichier
    FAPv0.4DPE-CDI.xlsm

  4. #4
    Expert confirmé
    Homme Profil pro
    aucune
    Inscrit en
    Septembre 2011
    Messages
    8 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : aucune

    Informations forums :
    Inscription : Septembre 2011
    Messages : 8 208
    Par défaut
    Mets :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Range("G12").Formula = "=VLOOKUP(B12,tableau2,2,0)"
    au lieu de

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Range("G12").Formula = "=VLOOKUP(B12,tableau2,2)"

  5. #5
    Membre régulier
    Homme Profil pro
    Technicien en Automatisme
    Inscrit en
    Novembre 2015
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Technicien en Automatisme

    Informations forums :
    Inscription : Novembre 2015
    Messages : 7
    Par défaut
    Merci beaucoup sa fonctionne !

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

Discussions similaires

  1. rendre invisible un bout de code en fonction d une radio box
    Par florianjoy54 dans le forum Général JavaScript
    Réponses: 7
    Dernier message: 13/02/2011, 14h14
  2. [AC-2007] Comment exécuter un code en fonction d'une valeur?
    Par tomga dans le forum VBA Access
    Réponses: 9
    Dernier message: 10/09/2009, 14h59
  3. Réponses: 4
    Dernier message: 08/08/2006, 15h04
  4. Regroupement de code à l'aide d'une fonction...
    Par JeremieT dans le forum Access
    Réponses: 6
    Dernier message: 09/01/2006, 10h53
  5. [VB6] Ajouter un commentaire à une fonction d'une DLL
    Par Ace303 dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 05/06/2003, 08h14

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