Copy a selected row in a listbox and fill a column to last row

AndyJM87

New Member
Joined
Aug 31, 2018
Messages
28
I will try and explain this as best as I can...

From a 2 column Listbox on a userform, I need to select a row and copy that row into a spreadsheet (columns C and D, from row 5 up to last row).

I have attached some images so you have an idea of what I am trying to do.

The code below will only change the last row... So C7 and D7. I need it to change the whole range up to last row.

Code:
Sub UpdateVRN()

Dim ws As Worksheet
Dim i As Long
Dim lRow As Long

Set ws = ThisWorkbook.Sheets("Data")

        lRow = ws.Range("B" & ws.Rows.Count).End(xlUp).row

    For i = 0 To frmChangeVRN.lstVRN.ListCount - 1

        If frmChangeVRN.lstVRN.Selected(i) Then
            ws.Cells(lRow, 4) = frmChangeVRN.lstVRN.List(i, 0)
            ws.Cells(lRow, 3) = frmChangeVRN.lstVRN.List(i, 1)
        End If
    
    Next i
    
End Sub

Update_zpswngvzvcl.png


Spreadsheet_zpsxfkmkapa.png
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
How about
Code:
If frmChangeVRN.lstVRN.Selected(i) Then
    Ws.Range("D5:D" & Lrow) = frmChangeVRN.lstVRN.List(i, 0)
    Ws.Range("C5:C" & Lrow) = frmChangeVRN.lstVRN.List(i, 1)
End If
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,397
Members
449,081
Latest member
JAMES KECULAH

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