Userform s'ouvrant par double-clique

vdh_xavier

XLDnaute Junior
Bonjour à tous,

J'ai un problème concernant une userform que j'active par un double clique sur un cellule.

Je ne sais pas comment exprimer le fait que les données entrées dans l'userform aillent se mettre dans la cellule qui a été double-cliquée.

Voici mes codes.

DOUBLE CLIQUE :
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("I6:I2000")) Is Nothing Then
Load UserForm1
UserForm1.Show
End If

USERFORM :
Private Sub Bt_AJD_Click()
Target.Value = UserForm1.TextBox1
End Sub


Il doit y avoir un problème au niveau du "Target.Value", parce que quand je mets [A1] = UserForm1.TextBox1, cela fonctionne.

J'ai essayé avec Target.Address ou en ajoutant une variable pour l'adresse du double-clique, mais je n'y arrive pas.

Je vous remercie d'avance pour votre aide.

Bonne journée

Xavier
 
Dernière édition:

vdh_xavier

XLDnaute Junior
Re : Userform s'ouvrant par double-clique

C'est gentil. Je reviendrai sur cette page alors pour vous envoyer mon code.

J'ai encore une petite question nocturne concernant l'ancien fichier : J'aimerais que mon DTPicker mette la date du jour par défaut. J'ai cherché sur internet et je pense avoir trouvé quelque chose, mais à mon avis je mets l'instruction que j'ai trouvée au mauvais endroit.

J'ai ceci :

Dim CelCbl As Range

Public Sub Afficher(ByVal Cible As Range)

Set CelCbl = Cible
Me.Show
Me.DTPicker1.Value = Now

End Sub

Private Sub Bt_Valider_Click()

CelCbl = DTPicker1.Value
Unload Me

End Sub

Private Sub Bt_Inconnue_Click()

' Le projet a été fait un autre jour (date inconnue), donc on met un "x" dans la cellule double-cliquée

CelCbl.Value = "X"
Unload Me

End Sub
Private Sub Bt_Annulation_Click()

'Si on ne veut rien mettre dans la cellule couble-cliquée, l'userform se ferme

Unload Me

End Sub

Private Sub UserForm_Click()

End Sub


Est-ce que je dois mettre l'instruction soulignée dans une nouvelle sub ou que dois-je faire?

Merci

Xavier
 

Dranreb

XLDnaute Barbatruc
Re : Userform s'ouvrant par double-clique

C'est toujours le même problème. Le Me.Show doit vraiment être la dernière instruction de la procédure Afficher. Tout ce qui vient derrière n'est exécuté qu'après la bataille. Je veux dire après l'un des différents Unload Me, et là ça ne sert plus à rien.
De toute évidence vous n'aviez rien compris à mon explication au #12 !
Je répète: l'exécution de la procédure Afficher reste bloquée sur le Me.Show jusqu'à ce que l'userform soit masqué ou déchargé.
 
Dernière édition:

Si...

XLDnaute Barbatruc
Re : Userform s'ouvrant par double-clique

salut

puisque c'était fait, une autre façon d'initialiser la date avant l'ouverture de l'UsF.
Une autre façon de trier selon la colonne avec effet bascule et encore par double clic (ligne 3 à copier dans ton classeur).
Ne pas oublier de copier, après avoir fait le ménage, les codes (page de la feuille et page de l'UsF).
 

Pièces jointes

  • initialisation Usf avant son ouverture.xls
    86 KB · Affichages: 32

vdh_xavier

XLDnaute Junior
Re : Userform s'ouvrant par double-clique

Salut Dranreb,

Je me permets d'encore te déranger pour te demander un tout petit coup de main.

En fait, j'ai un userform qui se lance par double-clic et qui demande à l'utilisateur s'il veut supprimer le ligne de la cible.

Lorsque je fais le double-clic, la ligne se supprime avec succès, mais après j'ai le message d'erreur suivant : La méthode 'Intersect' de l'objet '_Global' a échoué.

J'ai l'impression que "intersect" plante parce que la cible a évidemment disparu suite à la suppression de la ligne. Que puis-je faire pour que "intersect" se coupe juste après la suppression de la ligne?

Merci d'avance

Voici mes codes :

Double-clic

If Not Intersect(Target, Range("AQ6:AQ2000")) Is Nothing Then

ActiveSheet.Unprotect ("xavier")

UserForm8.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier"

Cancel = True

End If

Userform

Public Sub Afficher(ByVal Cible As Range)

Set CelCbl = Cible
Me.Show

End Sub

Private Sub Bt_Oui_Click()

CelCbl.EntireRow.Delete
Unload Me

End Sub

Private Sub Bt_Non_Click()

Unload Me

End Sub
 

Dranreb

XLDnaute Barbatruc
Re : Userform s'ouvrant par double-clique

Bonjour.
Je ne voie pas bien ce qui coince.
Pourquoi, pour une simple confirmation, n'utilisez vous pas plutôt un If Msgbox("Voulez vous supprimer la ligne ?", VbYesNo + VbQuestion, "Double clic") = VbYes Then ?
 

vdh_xavier

XLDnaute Junior
Re : Userform s'ouvrant par double-clique

Juste par souci d'uniformité. J'ai partout des userform et j'aimerais bien que la box pour supprimer une ligne soit la même que celles que j'ai pour les userform.

Est-ce que je peux vous envoyer mon fichier pour que vous regardiez?

Merci

Xavier
 

Dranreb

XLDnaute Barbatruc
Re : Userform s'ouvrant par double-clique

Vos conditions sont exclusives l'une de l'autre. Veillez à ne plus exécuter le reste lorsqu'une est vérifiée. Effectivement il se peut que Target ne soit plus initialisé si la ligne où il se trouvait a été supprimée.
Ne laissez qu'un End If à la fin et remplacez tous les If qui suivent le 1èr par des ElseIf.
Ou faites un Select Case Target.Address
Case "$A$4":
Case Is Like "$R$*"
Et appliquez une indentation correcte. Et tassez plus vos instructions: on ne voit dans une page qu'une tout petite partie du programme tellement c'est délayé par des lignes vides entre. Je fait exactement le contraire, mettant parfois plusieurs instructions sur la même ligne séparées par des ":" pour que mes procédures soient les plus courtes possible.
 

vdh_xavier

XLDnaute Junior
Re : Userform s'ouvrant par double-clique

Merci pour cette réponse.

J'ai opté pour la solution de mettre des ElseIf et de ne mettre un End If qu'à la fin et j'en ai protifé pour "nettoyer" mes instructions.

Cependant, lorsque je mets ElseIf, il me met "Else sans If".

Le ElseIf fonctionne-t-il aussi avec des If Not Intersect ?

Merci

Xavier
 

vdh_xavier

XLDnaute Junior
Re : Userform s'ouvrant par double-clique

C'est sûrement plus facile avec le code:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

'Double-clique sur les titres des colonnes pour lancer le tri

If Not Intersect(Target, Range("A4")) Is Nothing Then Application.Run ("Tri_par_nom")

ElseIf Not Intersect(Target, Range("D4")) Is Nothing Then Application.Run ("Tri_par_date_de_désignation")

ElseIf Not Intersect(Target, Range("E4")) Is Nothing Then Application.Run ("Tri_par_phase")

ElseIf Not Intersect(Target, Range("G4")) Is Nothing Then Application.Run ("Tri_par_Rappels_1")

ElseIf Not Intersect(Target, Range("J4")) Is Nothing Then Application.Run ("Tri_par_RDV")

ElseIf Not Intersect(Target, Range("R4")) Is Nothing Then Application.Run ("Tri_par_Rappels_2")

ElseIf Not Intersect(Target, Range("V4")) Is Nothing Then Application.Run ("Tri_par_CA_à_faire")

ElseIf Not Intersect(Target, Range("X4")) Is Nothing Then Application.Run ("Tri_par_Rappels_3")

ElseIf Not Intersect(Target, Range("AB4")) Is Nothing Then Application.Run ("Tri_par_RA_à_faire")

ElseIf Not Intersect(Target, Range("AD4")) Is Nothing Then Application.Run ("Tri_par_Rappels_4")

ElseIf Not Intersect(Target, Range("AJ4")) Is Nothing Then Application.Run ("Tri_par_RC_à_faire")

ElseIf Not Intersect(Target, Range("AL4")) Is Nothing Then Application.Run ("Tri_par_Rappels_5")

ElseIf Not Intersect(Target, Range("AO4")) Is Nothing Then Application.Run ("Tri_par_Rappels_6")

End If

' Insertion nouveau dossier

If Not Intersect(Target, Range("C2")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm0.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

End If

'Double clique sur les cellules pour y introduire quelque chose

If Not Intersect(Target, Range("R6:R2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm01.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

ElseIf Not Intersect(Target, Range("S6:S2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm02.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

ElseIf Not Intersect(Target, Range("X6:X2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm01.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

ElseIf Not Intersect(Target, Range("Y6:Y2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm02.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

ElseIf Not Intersect(Target, Range("AD6:AD2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm01.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

ElseIf Not Intersect(Target, Range("AE6:AE2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm02.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

ElseIf Not Intersect(Target, Range("AL6:AL2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm01.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

ElseIf Not Intersect(Target, Range("AM6:AM2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm02.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

ElseIf Not Intersect(Target, Range("AO6:AO2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm01.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

ElseIf Not Intersect(Target, Range("AP6:AP2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm02.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

ElseIf Not Intersect(Target, Range("I6:I2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm1.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

ElseIf Not Intersect(Target, Range("L6:L2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm2.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

ElseIf Not Intersect(Target, Range("N6:N2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm3.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

ElseIf Not Intersect(Target, Range("Q6:Q2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm4.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

ElseIf Not Intersect(Target, Range("T6:T2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm41.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

ElseIf Not Intersect(Target, Range("W6:W2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm5.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

ElseIf Not Intersect(Target, Range("AC6:AC2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm6.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

ElseIf Not Intersect(Target, Range("AK6:AK2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm7.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

ElseIf Not Intersect(Target, Range("AQ6:AQ2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm8.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

ElseIf Not Intersect(Target, Range("J6:J2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm9.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

ElseIf Not Intersect(Target, Range("O6:O2000")) Is Nothing Then ActiveSheet.Unprotect ("xavier"): UserForm9.Afficher Target

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:="xavier": Cancel = True

End If

End Sub
 

Dranreb

XLDnaute Barbatruc
Re : Userform s'ouvrant par double-clique

Cette forme de If ne supporte pas le ElseIf. Il ne faut pas d'instruction juste derrière le Then, mais sur une nouvelle ligne. Je sais ça va à l'encontre d'un gain de compacité du code comme je l'aime à l'extrême…
 

Discussions similaires

Statistiques des forums

Discussions
312 231
Messages
2 086 450
Membres
103 214
dernier inscrit
MASSA1616