Microsoft 365 Erreur 9 sur macro VBA

oceeaa

XLDnaute Nouveau
Bonjour,

J'ai réalisé une macro sur VBA seulement lorsque je l'exécute une erreur "9" s'affiche. J'ai fait des recherches mais je ne parviens pas à comprendre comment la supprimer.
J'ai réalisé des listes déroulantes dépendantes.
Une capture d'écran de ce que je souhaite obtenir est sur le fichier excel

Je vous remercie d'avance!
 

Pièces jointes

  • VBA 1.xlsm
    128.7 KB · Affichages: 9

soan

XLDnaute Barbatruc
Inactif
Bonsoir oceeaa, ChTi160,

ton fichier en retour. :)

* fais Ctrl e ; regarde B2 ; appuie sur la touche Echap ➯ sortie du formulaire

* fais Ctrl e ; regarde la liste No Commercial ; y'a bien 1 à 3 (c'était pareil avant de faire Echap)

* choisis un autre jour, et regarde la liste No Commercial (elle se met à jour correctement)

* fais pareil qu'au point précédent, pour tester selon plusieurs jours différents.

* quand t'auras fini de jouer avec ton formulaire, clique sur le bouton Fermer.​



code VBA (40 lignes) :

VB:
Option Explicit

Dim dcol%

Private Sub cbjour_Change()
  Dim dlg&, col%: col = cbjour.ListIndex + 2
  dlg = Cells(Rows.Count, col).End(3).Row: If dlg < 3 Then Exit Sub
  cbnocommercial.Clear 'on vide la liste déroulante des commerciaux
  If dlg = 3 Then
    cbnocommercial = Cells(3, col)
  Else
    cbnocommercial.List = Cells(3, col).Resize(dlg - 2).Value
    cbnocommercial.ListIndex = 0
  End If
  'on retire les couleurs des en-têtes
  With [B2].Resize(, dcol - 1)
    With .Font: .ColorIndex = -4105: .Bold = 0: End With
    .Interior.ColorIndex = -4142
  End With
  'on met une couleur de remplissage pour le jour choisi
  With Cells(2, col)
    With .Font: .ColorIndex = 2: .Bold = -1: End With
    .Interior.ColorIndex = 32
  End With
End Sub

Private Sub cbjour_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
  If KeyAscii = 27 Then Unload Me
End Sub

Private Sub cmdQuit_Click()
  Unload Me
End Sub

Private Sub UserForm_Initialize()
  dcol = Cells(2, Columns.Count).End(1).Column: If dcol = 1 Then Exit Sub
  cbjour.List = Application.Transpose([B2].Resize(, dcol - 1).Value)
  cbjour.ListIndex = 0
End Sub

si besoin, tu peux demander une adaptation.
à te lire pour avoir ton avis.


soan
 

Pièces jointes

  • VBA 1.xlsm
    23.6 KB · Affichages: 3

Statistiques des forums

Discussions
312 081
Messages
2 085 161
Membres
102 800
dernier inscrit
NOTZ