'Write Selected Listbox values to sheet, only one selection is being written

I am trying to write the selected values form a listbox to a sheet in excel. Only the first selected value is being written.

The code segment being used is:

numofformulas = WorksheetFunction.CountA(Sheets("Costs").Range("D:D")) - 1
k = 0
For i = 0 To numofformulas
    If UserForm3.ListBox1.Selected(i) = True Then
        Sheets("PriceSheet").Cells(k + 7, 3) = UserForm3.ListBox1.List(i)
        k = k + 1
    End If
Next i

I was stepping through the code and realized that after the:

Sheets("PriceSheet").Cells(k + 7, 3) = UserForm3.ListBox1.List(i)

line the selection is cleared and they all revert to false so only the first line is writing to the cells. any idea how to stop that clearing?



Solution 1:[1]

Here are the proper settings for check list.

ListStyle

ListStyle Property

MultiSelect

MultiSelect Property

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TinMan