XL 2013 Problème de code VBA avec "Application.Intersect"

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

karinette

XLDnaute Occasionnel
Bonjour à tous.
J'ai un soucis de code, j'ai beau le modifier, je sèche ....
J'ai une feuille où j'aimerais avoir deux fonctions différentes en faisant un double click.
dans les cellules "$A$4:$A$35000", en double-cliquant, ça me lance un Userform.
Ce que j'aimerais, c'est qu'en double-cliquant dans les cellules "$K$4:$K$35000" ça me lance un Userform different ...
J'ai fait ce code ... ça fonctionne tès bien sur la première série, (le USF "saisie_modif" se lance) mais pas sur l'autre (il ne se passe rien !!).
Merci d'avance aux experts !!!

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Application.Intersect(Target, Range("$A$4:$A$35000")) Is Nothing Then
If ActiveCell.Value <> "" Then
Application.Run "saisie_modif"
End If
If Not Application.Intersect(Target, Range("$K$4:$K$35000")) Is Nothing Then
If ActiveCell.Value <> "" Then
Application.Run "saisie_horaire"
End If
ElseIf ActiveCell.Value = "" Then
Range("A1").Select
MsgBox "Impossible !"
End If
End If
End Sub
 
Bonsour®
Bonjour à tous.
J'ai un soucis de code, j'ai beau le modifier, je sèche ....
J'ai une feuille où j'aimerais avoir deux fonctions différentes en faisant un double click.

comme ceci peut-être ?? :
VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Application.Intersect(Target, Range("$A$4:$K$35000")) Is Nothing Then
         If Target<> "" Then
             Select Case Target.column
                 Case =1 : Application.Run "saisie_modif"
                 Case = 11 : Application.Run "saisie_horaire"
                 '*******Case = ? : autre userfrom
                Case Else :MsgBox "Impossible !"
           End Select
       End If
   Else
       Range("A1").Select
   End If
End Sub
 
Dernière édition:
Bonjour,

sans fichier impossible de tester. Pour ouvrir un userform, on met nomUserform.show

si tu as nommé ton userform: saisie_modif
tu dois remplacer Application.Run "saisie_modif" par ----> saisie_modif.show

bonne continuation.

edit: Bonjour Modeste geedee
 
Bon_jour

Essaie ce code
VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal R As Range, Cancel As Boolean)
    If Not Application.Intersect(R, Range("A4:A35000,K4:K35000")) Is Nothing Then
      Cancel = 1
      If R <> "" Then
          If R.Column = 1 Then Application.Run "saisie_modif" Else Application.Run "saisie_horaire"
      Else
          [A1].Select: MsgBox "Impossible !"
      End If
  End If
End Sub
Tu pourrais aussi corriger le tien ainsi,
VB:
Dim i As Boolean  'ne pas supprimer ni déplacer
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  If Not Application.Intersect(Target, [A4:A35000]) Is Nothing Then
      If Target <> "" Then i = 1: Application.Run "saisie_modif": Exit Sub
  End If
  If Not Application.Intersect(Target, [K4:K35000]) Is Nothing Then
      If Target <> "" Then i = 1: Application.Run "saisie_horaire": Exit Sub
  End If
  If i = 1 Then [A1].Select: MsgBox "Mission Impossible !"
End Sub

Modeste (oui pour le Select Case plus approprié pour des cas nombreux et indépendants) ton message n'apparait jamais donc il devient est inutile 😳.
On pourrait le transformer ainsi :
VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  If Not Application.Intersect(Target, Range("$A$4:$K$35000")) Is Nothing Then
      If Target <> "" Then
          Select Case Target.Column
              Case 1: Application.Run "saisie_modif"
              Case 11: Application.Run "saisie_horaire"
               '*******Case = ? : autre userfrom
         End Select
      Else
          MsgBox "Impossible !"
          Range("A1").Select
      End If
    End If
End Sub
Mais, à cause du Range("$A$4:$K$35000"), il apparaîtrait trop souvent.

Je me demande, finalement, si cette alerte est vraiment nécessaire !
 
Bon_jour

Essaie ce code
VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal R As Range, Cancel As Boolean)
    If Not Application.Intersect(R, Range("A4:A35000,K4:K35000")) Is Nothing Then
      Cancel = 1
      If R <> "" Then
          If R.Column = 1 Then Application.Run "saisie_modif" Else Application.Run "saisie_horaire"
      Else
          [A1].Select: MsgBox "Impossible !"
      End If
  End If
End Sub
Tu pourrais aussi corriger le tien ainsi,
VB:
Dim i As Boolean  'ne pas supprimer ni déplacer
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  If Not Application.Intersect(Target, [A4:A35000]) Is Nothing Then
      If Target <> "" Then i = 1: Application.Run "saisie_modif": Exit Sub
  End If
  If Not Application.Intersect(Target, [K4:K35000]) Is Nothing Then
      If Target <> "" Then i = 1: Application.Run "saisie_horaire": Exit Sub
  End If
  If i = 1 Then [A1].Select: MsgBox "Mission Impossible !"
End Sub

Modeste (oui pour le Select Case plus approprié pour des cas nombreux et indépendants) ton message n'apparait jamais donc il devient est inutile 😳.
On pourrait le transformer ainsi :
VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  If Not Application.Intersect(Target, Range("$A$4:$K$35000")) Is Nothing Then
      If Target <> "" Then
          Select Case Target.Column
              Case 1: Application.Run "saisie_modif"
              Case 11: Application.Run "saisie_horaire"
               '*******Case = ? : autre userfrom
         End Select
      Else
          MsgBox "Impossible !"
          Range("A1").Select
      End If
    End If
End Sub
Mais, à cause du Range("$A$4:$K$35000"), il apparaîtrait trop souvent.

Je me demande, finalement, si cette alerte est vraiment nécessaire !

Ce code est parfait !!
Le message, c'est juste pour prévenir, en théorie il ne devrait pas apparaitre, mais bon ...
Je ne connaissais pas le principe du "Select Case" en validant les deux plages de cellules ... j'ai encore découvert des choses !!! En tout les cas, un grand merci à tous !!!!
 
Bonsour®

On pourrait le transformer ainsi :
VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  If Not Application.Intersect(Target, Range("$A$4:$A$35000","$K$4:$K$35000")) Is Nothing Then
          If Target <> "" Then
              Select Case Target.Column
                          Case 1: Application.Run "saisie_modif"
                          Case 11: Application.Run "saisie_horaire"
                           '*******Case = ? : autre userfrom
              End Select
          End If
  Else
          MsgBox "Impossible !"
          Range("A1").Select
   End If
End Sub
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

  • Question Question
Microsoft 365 Probléme VBA
Réponses
8
Affichages
239
  • Question Question
Microsoft 365 worksheet_change
Réponses
29
Affichages
274
Réponses
14
Affichages
376
Réponses
4
Affichages
367
Retour