VBA Userform Scrollable Listbox displaying incorrect value

  • I am a beginner in VBA.

    In a userform that I create, I add a scrollable listbox (3 columns, 12 rows)and a button.

    When I click the button, the value in the third column should change, and the listbox should display the new value accordingly.

    However, currently there are particular rows fail to display the new value even I change it already. And I also notice that the rows that fail to display the new value are those not showing in the scrollable list box when I click the button.

    Does anyone know why this happen. Thank you so much!!!

  • You need to attach an example of your workbook.

    Hi, thanks for the reply. I tried to attached the example workbook but it said the file extension is invalid, so I post the code and screenshot below.

    As you can see, I click the button once which increase the second column of each row by 1 successfully.

    However, when I click the button second time, the rows that are not display in the scrollable listbox at the moment, fail to increase by 1 again

    Below is the code in the example. Thank you so much.

  • Hello

    I think is better to change your code on CommandButton1 like this

    Private Sub CommandButton1_Click()
        For i = lstProducts.ListCount - 1 To 0 Step -1
            lstProducts.List(i, 1) = lstProducts.List(i, 1) + 1
        Next i
    End Sub

    Hope it helps. Hello,


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!