I have a list box populated from SQL database, I would like to export the selected items from the list box to an excel sheet. What I can't work out is how to past each selected item from listbox in different cells. I have the code to drop down a row each time but cant figure out how to put it together with the selected items block of code.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim NewExcel As New Excel.Application
NewExcel.Workbooks.Add()
Dim counter As Integer = 0
Dim SelectedItems = (From i In ListBox1.SelectedItems).ToList
For Each selectedItem In SelectedItems
NewExcel.Range("A1").Value = ListBox1.SelectedItem
Next
'Do
' NewExcel.ActiveCell.Value = counter
' NewExcel.ActiveCell.Offset(1, 0).Activate()
' counter += 1
'Loop Until counter = 10
NewExcel.Visible = True
End Sub