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

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
 

Modeste geedee

XLDnaute Barbatruc
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:

cp4

XLDnaute Barbatruc
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
 

Si...

XLDnaute Barbatruc
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 :oops:.
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 !
 

karinette

XLDnaute Occasionnel
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 :oops:.
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 !!!!
 

Modeste geedee

XLDnaute Barbatruc
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
 

Discussions similaires

Réponses
2
Affichages
136

Membres actuellement en ligne

Statistiques des forums

Discussions
312 196
Messages
2 086 100
Membres
103 116
dernier inscrit
kutobi87