Hello Stackoverflow community
I require help with a ListBox error.
I have two ListBoxes in a worksheet (single select) & not in a userform
ListBox1 - contains primary items
ListBox2 - contains sub items associated with the primary items
When a primary item is selected -
If no sub items exist, ListBox2.Visible = False
If sub items exist, ListBox2.Visible = True and .ListIndex = -1 (ready for sub item selection)
Code runs perfectly when using the workbook
Issue When workbook is opened, the macro linked to ListBox1 will run automatically and and error will pop up, highlighting in blue '.ListBox2'
Error = 'Compile Error: Method or Data Member not found'
The Error does not happen all the time, and does not matter if the workbook is saved with ListBox2 visible or not, or a sub item selected or not.
I have tried using on open workbook events, but the error comes before these events.
Please help
Added code where error occurs
Dim ListBox2 As ListObject 'Added this in to see if it fixes error but it has not
With Sheet3.ListBox2
.Height = 208.5
.Width = 126.75
.Top = 312.75
.Left = 31.5
.Visible = False
End With
Option Explicit
to the very top of the module (and every module, always) and then try compiling the code to see if that sheds some light on which variables/objects you have not properly declared. Note that it will probably produce several errors that you need to fix one at a time; this is a good thing. – ashleedawglistbox2
properly, maybe an undeclared variable or object? (Also, the compiler will only stop on the first error in the module regardless of how many times you have used it... It "doesn't know" about the other errors yet because it hasn't made it past your first mistake yet.) – ashleedawg