Copy the LISTBOX data in the first empty row

sofas

Active Member
Joined
Sep 11, 2022
Messages
493
Office Version
  1. 2019
Platform
  1. Windows
Hello I have this code to copy the filtered data to the result sheet but it copies over the old data how can I make it copy under the last row it has a value


VBA Code:
Private Sub test_Click()
  Set f2 = Sheets("résultat")
  'f2.Cells.ClearContents
  a = Me.ListBox1.List
  f2.[A2].Resize(UBound(a) + 1, UBound(a, 2) + 1) = a
  c = 0
  'For c = 1 To NbCol
     'f2.Cells(1, c) = Range(NomTableau).Offset(-1).Item(1, c)
 ' Next
 ' f2.Cells.EntireColumn.AutoFit
End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
maybe find the last row
Lrow = Acivesheet.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

then use that instead of 1
f2.Cells(lrow +1, c) = Range(NomTableau).Offset(-1).Item(1, c)
lrow = lrow +1
 
Upvote 0
maybe find the last row
Lrow = Acivesheet.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

then use that instead of 1
f2.Cells(lrow +1, c) = Range(NomTableau).Offset(-1).Item(1, c)
lrow = lrow +1
Unfortunately it didn't work for me
 
Upvote 0
I tried to put it in this way but unfortunately without result

VBA Code:
Private Sub test_Click()
Application.ScreenUpdating = False
  Set f = Sheets("Filter")
    With f
     lastRow = .Cells(.Rows.Count, "a").End(xlUp).row + 1
End With
  n = ListBox1.ListCount
  Tbl = Me.ListBox1.List
 
  f.[a6].Resize(n, 5) = Application.Index(Tbl, Evaluate("Row(a:lastrow" & n & ")"), Array(1, 2, 3, 4, 8))
  c = 0
 
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,790
Members
449,468
Latest member
AGreen17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top