• Initiateur de la discussion Initiateur de la discussion ThierryR
  • Date de début Date de début

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 !

T

ThierryR

Guest
Bonjour à tous,

J'ai deux listbox SuiviBP (3 colonnes) et RapprochementBP (5 colonnes). Je prends un élément de SuiviBP et je le mets dans RapprochementBP. Jusque là tout marche mais je voudrai transférer SuiviBP dans les 3ères colonnes de RapprochementBP : la cela coince... 🙂 une ligne à la suite de l'autre après chaque drag and drop.
Voici mon bout de programme inspiré maladroitement selon l'exemple de @Thierry USF_Drag_N_Drop_To_Cells.xls :

Private Sub RapprochementBP_BeforeDropOrPaste(ByVal Cancel As MSForms.ReturnBoolean, ByVal Action As MSForms.fmAction, ByVal Data As MSForms.DataObject, ByVal X As Single, ByVal Y As Single, ByVal Effect As MSForms.ReturnEffect, ByVal Shift As Integer)
Dim Ligne As Integer

Cancel = True
Effect = 1
If SuiviBP.ListCount >= 1 Then
If SuiviBP.ListIndex = -1 Then
SuiviBP.ListIndex = SuiviBP.ListCount - 1
End If
Ligne = RapprochementBP.ListCount + 1
With RapprochementBP
.AddItem SuiviBP.Column(0, SuiviBP.ListIndex)
.Column(1, 0) = SuiviBP.Column(1, (SuiviBP.ListIndex))
.Column(2, 0) = SuiviBP.Column(2, (SuiviBP.ListIndex))
.Column(3, 0) = SuiviBP.Column(3, (SuiviBP.ListIndex))
End With
End If

End Sub

Merci d'avance pour votre aide

ThierryR
 
Une première rectification :

Private Sub RapprochementBP_BeforeDropOrPaste(ByVal Cancel As MSForms.ReturnBoolean, ByVal Action As MSForms.fmAction, ByVal Data As MSForms.DataObject, ByVal X As Single, ByVal Y As Single, ByVal Effect As MSForms.ReturnEffect, ByVal Shift As Integer)
Dim Ligne As Integer

Cancel = True
Effect = 1
If SuiviBP.ListCount >= 1 Then
If SuiviBP.ListIndex = -1 Then
SuiviBP.ListIndex = SuiviBP.ListCount - 1
End If
Ligne = RapprochementBP.ListCount + 1
With RapprochementBP
.AddItem SuiviBP.Column(0, SuiviBP.ListIndex)
.Column(1, Ligne) = SuiviBP.Column(1, (SuiviBP.ListIndex))
.Column(2, Ligne) = SuiviBP.Column(2, (SuiviBP.ListIndex))
End With
End If

End Sub
 
Je progresse dans mon cheminement :

Private Sub RapprochementBP_BeforeDropOrPaste(ByVal Cancel As MSForms.ReturnBoolean, ByVal Action As MSForms.fmAction, ByVal Data As MSForms.DataObject, ByVal X As Single, ByVal Y As Single, ByVal Effect As MSForms.ReturnEffect, ByVal Shift As Integer)
Dim Ligne As Integer

Cancel = True
Effect = 1
If SuiviBP.ListCount >= 1 Then
If SuiviBP.ListIndex = -1 Then
SuiviBP.ListIndex = SuiviBP.ListCount - 1
End If

If RapprochementBP.ListCount = 0 Then
Ligne = 0
Else
Ligne = RapprochementBP.ListCount
End If

With RapprochementBP
.AddItem SuiviBP.Column(0, SuiviBP.ListIndex)
.Column(1, Ligne) = SuiviBP.Column(1, (SuiviBP.ListIndex))
.Column(2, Ligne) = SuiviBP.Column(2, (SuiviBP.ListIndex))
End With
End If

End Sub

Ma question consécutive à cela :
Selectionner dans les deux listbox et faire drag and drop avec les deux selections.

Merci d'avance à tous

ThierryR
 
- 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
Assurez vous de marquer un message comme solution pour une meilleure transparence.

Discussions similaires

  • Question Question
Microsoft 365 worksheet_change
Réponses
29
Affichages
266
Réponses
4
Affichages
511
Réponses
4
Affichages
161
Réponses
16
Affichages
1 K
Retour