0

I have the following code that adds items from a list box starting in Cell A15, if I go back into the list box, it rewrites over the first items, how can I have it start on the first empty row starting at 15? Code below

Private Sub CommandButton3_Click()
   Dim lngLastRow As Long
   Dim lngCol As Long
   Dim lngIndex As Long
   For lngIndex = 0 To ListBox2.ListCount - 1
      Cells(lngIndex + 15, 1).Value = ListBox2.List(lngIndex)
   Next
   Unload Me
End Sub 

Having trouble figuring out the if thens

2
  • 1
    See: stackoverflow.com/questions/11169445/… on how to find the last row with a value. Then you can replace the 15 with that. Commented Jul 11, 2023 at 19:05
  • I changed the code as follows, and i am getting an error with replacing the 15. Cells(lngIndex + LastRow, 1).Value = ListBox2.List(lngIndex) Commented Jul 12, 2023 at 11:40

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.