Excel VBA : Selecting Sheet based on the Drop down list name. Run time error 9 - Subscript out of range. Error -


i have written below line of code navigating sheet according drop down list item selected. works first time run time error 9 - subscript out of range error, when attempt next time. getting error in line
"activeworkbook.sheets(cbodependentlist.value).activate"

below line of code:

'populate dependent combo box appropriate list items                                  'according selection in cbocategorylist. sub test()                                                        dim rng range        dim ws worksheet         dim str string           set ws = worksheets("lists")          str = cbocategorylist.value           me.cbodependentlist.clear             on error resume next              each rng in ws.range(str)               me.cbodependentlist.additem rng.value            next rng           end sub  sub cbodependentlist_change()               activeworkbook.sheets(cbodependentlist.value).activate       end sub  private sub worksheet_activate()              'populate combo box inventory categories.              dim rng range              dim ws worksheet              set ws = worksheets("lists")              me.cbocategorylist.clear              each rng in ws.range("category")                me.cbocategorylist.additem rng.value                 next rng                        end sub              

at times debugger of excel doesn't highlight line of code triggers error, instead highlights 1 of callers (higher in call stack).

in case activate method might not directly causing run time error 9 - subscript out of range error, effect in subroutine worksheet_activate might. advise set breakpoint on line calling activate, , step through code in debug mode. if doesn't work might have set breakpoint @ start of subroutine worksheet_activate.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -