Copier ListBox vers Feuille

Bonjour à le forum,

Attention : Je sais que ce sujet a déjà été traité mais il y a une subtilité que je n'arrive pas à trouver sur internet.

J'ai une Listbox avec 4 colonnes : "Nom_Livre", "Auteur", "Quantité" et "Prix".

Quand je lance mon Userform, j'aimerais copier dans la feuille 2 uniquement les colonnes 2, 3 et 4 (donc toutes sauf la colonne "Nom_livre").

J'arrive à copier les 4 mais malheureusement je n'ai pas réussi à faire ce que je voulais.

J'ai utiliser ce code :

Private Sub CommandButton1_Click()
Sheets("Feuil2").Activate
Sheets("Feuil2").Range("A1:C3").ClearContents
Sheets("Feuil2").Range("A1").Resize(Me.ListBox1.ListCount, 4).Value = ListBox1.List
End Sub

Merci pour toute aide !

Amitiés

Bonjour,

Un essai ...

Une façon parmi tant d'autres ...

Private Sub CommandButton1_Click()
Dim X As Integer
Dim Y As Integer
Dim Z As Byte

   X = Me.ListBox1.ListCount

   Sheets("Feuil2").Activate
   Sheets("Feuil2").Range("A1:C3").ClearContents

   For Y = 1 To X
      For Z = 1 To 3
         Sheets("Feuil2").Cells(Y, Z).Value = Me.ListBox1.List(Y - 1, Z)
      Next Z
   Next Y
End Sub

ric

Bonsoir MPETIT, ric, le forum,

Une autre façon de procéder....

Option Explicit
Dim X As Integer, dl As Integer, i As Integer
Dim nbcol As Integer
Dim f As Worksheet, rng As Range, tblbd

Private Sub UserForm_Initialize()
    Set f = Sheets("Feuil1")
  Set rng = f.Range("A1:D" & Range("A" & Rows.Count).End(xlUp).Row)
    nbcol = rng.Columns.Count
   Me.ListBox1.ColumnCount = nbcol
   Me.ListBox1.ColumnWidths = "70;70;50;50"
    tblbd = rng.Value
    For i = 1 To UBound(tblbd): tblbd(i, 4) = Format(tblbd(i, 4), "0.00 €"): Next i
   Me.ListBox1.List = tblbd
    ListBox1.Selected(0) = True
End Sub

Private Sub CommandButton1_Click()

 Application.ScreenUpdating = False

   With Sheets("Feuil2")
    .Activate
    .Range("A1").CurrentRegion.ClearContents
    dl = .Range("A" & Rows.Count).End(xlUp).Row + 1

   For X = 1 To Me.ListBox1.ListCount
       .Range("A1:C1").Font.Bold = True
       .Cells(X, 1) = Me.ListBox1.List(X - 1, 1)
       .Cells(X, 2) = Me.ListBox1.List(X - 1, 2)
       .Cells(X, 3) = Me.ListBox1.List(X - 1, 3)
    Next X
   End With
    Unload Me
End Sub

Bonne soirée,

Bonjour à vous deux, le forum,

C'est parfait et ça me convient !

Bien cordialement,

Amitiés

Rechercher des sujets similaires à "copier listbox feuille"