copy specific columns from listbox to userform without selection

Ali M

Active Member
Joined
Oct 10, 2021
Messages
348
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
Hello ,
I would copy specific columns from listbox to bottom in sheet without selected from listbox.
any idea to fix this code please?


VBA Code:
Dim lastrow As Long
     With Sheet2
        .Range("A" & lastrow + 1).Value = Me.ListBox1.Column(0)
        .Range("B" & lastrow + 1).Value = Me.ListBox1.Column(1)
        .Range("C" & lastrow + 1).Value = Me.ListBox1.Column(3)
    End With
thanks
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I have another code to show data on form based on another sheet . so what I would do it by commandbutton to copy specific columns to sheet.
data could be 8000 rows .
 
Upvote 0
That is, you want to copy certain columns from all the rows that are displayed in your listbox, do I understand you correctly?
 
Upvote 0
Hi Dave,
I try this
VBA Code:
With Me.ListBox1
        Sheet2.Range("A1").Resize(.ListCount).Value = Application.Index(.List, 0, 0)
        Sheet2.Range("B1").Resize(.ListCount).Value = Application.Index(.List, 0, 1)
        Sheet2.Range("C1").Resize(.ListCount).Value = Application.Index(.List, 0, 3)
        
    End With
but show mismatch error starting from first line after listbox1 !
 
Upvote 0
That is, you want to copy certain columns from all the rows that are displayed in your listbox, do I understand you correctly?
yes
 
Upvote 0
The solution is in the link that was provided to you.
 
Upvote 0
Hi Dave,
but show mismatch error starting from first line after listbox1 !

need to start with 1 for first column
VBA Code:
  With Me.ListBox1
        Sheet2.Range("A1").Resize(.ListCount).Value = Application.Index(.List, 0, 1)
        Sheet2.Range("B1").Resize(.ListCount).Value = Application.Index(.List, 0, 2)
        Sheet2.Range("C1").Resize(.ListCount).Value = Application.Index(.List, 0, 4)
       
    End With

Dave
 
Upvote 0
need to start with 1 for first column
well, I thought the first column in listbox takes zero !:oops:
even if I change to 1 still shows error !
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,107
Members
453,021
Latest member
Justyna P

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