I'm developing a program within Excel and VBA, and am getting a run time error 380 when I try to change the selected property of a listbox.
The property is determined by a column on an excel spreadsheet, containing True or False values. I've printed the contents of these cells to the console and can confirm that the true/false values are working correctly, however when I try to assign these values to my listbox.selected property I get an error.
The function is below, any help or suggestions would be much appreciated.Error occurs on this line:
ElementListBox.Selected(count - 1) = TaskListSheet.Cells(TaskListCellRef(Task, ref.Row) + count + 1, TaskBreakdownColumnRefs(TaskBreakdownColumnHeaders.Included)).Value
Public Function LoadTier2SubTaskList(ByVal Task As Single, ByRef ElementListBox As Control)
ElementListBox.Clear
WorklistComboBox.Clear
Dim count As Single
Dim finished As Boolean
Dim TaskListSheet As Worksheet
Set TaskListSheet = TBSheet
finished = False
For count = 1 To 50
Next count
count = 1
Dim TaskString As String
Do While finished = False
TaskString = TaskListSheet.Cells(TaskListCellRef(Task, ref.Row) + count + 1, TaskBreakdownColumnRefs(TaskBreakdownColumnHeaders.ElementOfWork)).Text
If TaskString = vbNullString Then
finished = True
ElseIf TaskListSheet.Cells(TaskListCellRef(Task, ref.Row) + count + 1, TaskBreakdownColumnRefs(TaskBreakdownColumnHeaders.Tier)).Value = 2 Then
ElementListBox.AddItem (TaskString)
ElementListBox.Selected(count - 1) = TaskListSheet.Cells(TaskListCellRef(Task, ref.Row) + count + 1, TaskBreakdownColumnRefs(TaskBreakdownColumnHeaders.Included)).Value
Debug.Print (TaskListSheet.Cells(TaskListCellRef(Task, ref.Row) + count + 1, TaskBreakdownColumnRefs(TaskBreakdownColumnHeaders.Included)).Value)
End If
count = count + 1
Loop
End Function