VBA Code from listbox to worksheet

Eve05

New Member
Joined
Sep 21, 2020
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi
I have a worksheet that has 2 userforms. I have a VBA code that allows the selected records to show in a specific cells, but when I select another one it goes over the top of the first one, i need it to appear and the next blank row. Can anyone tell me what I am doing wrong.

VBA Code:
Private Sub cmdAdd_Click()
    Dim addme As Range
    Dim x As Integer
    Set addme = Sheet1.Range("C6").End(xlUp).Offset(1, 0)
    For x = 0 To Me.lstData.ListCount - 1
        If Me.lstData.Selected(x) Then
            addme = Me.lstData.List(x)
            addme.Offset(0, 1) = Me.lstData.List(x, 1)
            addme.Offset(0, 2) = Me.lstData.List(x, 2)
            addme.Offset(0, 3) = Me.lstData.List(x, 3)
            addme.Offset(0, 4) = Me.lstData.List(x, 4)
            addme.Offset(0, 5) = Me.lstData.List(x, 5)
            addme.Offset(0, 6) = Me.lstData.List(x, 6)
            addme.Offset(0, 7) = Me.lstData.List(x, 7)
            addme.Offset(0, 8) = Me.lstData.List(x, 8)
            
            Set addme = addme.Offset(1, 0)
        End If
    Next x
    For x = 0 To Me.lstData.ListCount - 1
        If Me.lstData.Selected(x) Then Me.lstData.Selected(x) = False
    Next x
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi.

Try after replace this line ~~~> Set addme = Sheet1.Range("C6").End(xlUp).Offset(1, 0)

by this ~~~> Set addme = Sheet1.Cells(Rows.Count, 3).End(xlUp).Offset(1, 0)
 
Upvote 0

Forum statistics

Threads
1,214,601
Messages
6,120,467
Members
448,965
Latest member
grijken

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