Don't have much experience with forms/listboxes. The following function aims to remove an array element by passing it to ListBox
and using ListBox.RemoveItem
method. What i am struggling with is creating/deleting ListBox
object programmatically. I do know there are ActiveX and Form ListBox
types but recording a code by adding both manually looks identical:
ActiveSheet.ListBoxes.Add(273, 289.5, 72, 71.25).Select
Here is the attempted function:
Function ArraylessElement(arrIn As Variant, ElemNo As Integer) As Variant
''''''''''''''''''''''''''''''''
'removes i element from 1D array by assigning to ListBox
'returns 1D array w/ Transpose
''''''''''''''''''
Dim lBox As ListBox
With ActiveSheet
Set lBox = .ListBoxes.Add(261, 279.75, 72, 71.25)
lBox.List = arrIn
lBox.RemoveItem (ElemNo - LBound(arrIn) - 1) '(LBound) of a ComboBox/ ListBox is 0.
ArraylessElement = Application.Transpose(lBox.List)
lBox.Delete
End With
End Function
I'm getting
Unable to set the list property of the ListBox class
error on lBox.List = arrIn
line.
PS. I did see a DeleteArrayElement
function at http://www.cpearson.com/excel/vbaarrays.htm which i will use if i cannot get mine working.