0 votes
in VBA by Beginner (69 points)

hi

i would   ask  if  i  can  highlight the  5 last  row in  listbox    directly  when run  userform without  select  item   by  vba  exel    like  this 

1 Answer

0 votes
by Expert (916 points)

Try this

    Dim cnt As Long
    For i = ListBox1.ListCount - 1 To 0 Step -1
        cnt = cnt + 1
        ListBox1.Selected(i) = True
        If cnt = 5 Then Exit For
    Next i

 

by Beginner (69 points)
hi,  YasserKhalil it  doesn't  show  any  thing i put  in  event userform initalize and  listbox1_click  it doesn't show  anything
by Expert (916 points)
This worked on my side in UserForm_Initialize event. Attach your sample workbook to have a look. Make sure you have changed the properties of ListBox to allow multiple selections.

Welcome to wellsr Q&A
Ask any questions you have about VBA and Python and our community will help answer them. wellsr Q&A is the standalone question and answer platform for wellsr.com. If you have a question about one of our specific tutorials, please include a link back to the tutorial.

Getting Started
Register
VBA Cheat Sheets (On Sale Now)

Looking for something else? Hire our team directly through ourVBA Help page, instead.

For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.

...