none
Issue to select a line of a ListBox control with VBA code RRS feed

  • Question

  • Dear developers/contributors,

    I have difficulties trying to select a line of a ListBox control by using only VBA code.

    For instance, this code works perfectly :

    myListBox.value = "30"
    myListBox.ListIndex = 45

    -> The target lines are selected properly in the ListBox control.

    But when trying to assign the property with a custom variable, it fails (ie. no selection in the ListBox occurs) :

    Dim myValue as string
    Dim myLine as Integer
    
    myListBox.value = myValue
    myListBox.ListIndex = maLine

    It works only when using a constant hard-coded.

    Do you have any explanation about this issue. Is it a bug? Is there any workaround?

    I thank you very much in advance for your valued help!

    Robin

    Friday, October 4, 2013 2:24 PM

All replies

  • Looks like typo...
    maLine  should be  myLine

    Also, myLine should be assigned a value...
    Dim myLine as Long
    myLine = 45
    '---
    Jim Cone
    Portland, Oregon USA
    https://goo.gl/IUQUN2 (Dropbox)
    (free & commercial excel add-ins & workbooks)

    • Edited by James Cone Sunday, October 30, 2016 7:45 PM
    Sunday, October 6, 2013 9:06 PM