Scroll vertical scrollbar to the bottom of list

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Hi
Can I get a script to scroll the vertical scrollbar to the bottom of the list of a listbox?

I load the listbox each time I add data . So I will like to see the last item.

Thanks
 
I am using a listbox and I have no idea what the listview is.

Code:
Sub LookupCurrentName()
    Me.lstView.ColumnCount = 27
    Dim myArray As Variant
    myArray = [c7].Resize(, Me.lstView.ColumnCount + 1).Value
    Me.lstView.List = myArray
    Me.lstView.Clear
    term = Me.CmbClass.Value
    With Sheets(term).Range("C7:C1007")
    Set rngFind = .Find(what:=Me.Rw2.Text, After:=Sheets(term).[C1007], LookIn:=xlValues, lookat:=xlWhole, SearchDirection:=xlNext)
    If Not rngFind Is Nothing Then
        strFirstFind = rngFind.Address
    Do
    If rngFind.Row > 1 Then
        Me.lstView.AddItem rngFind.Offset(0, -1).Text
    For i = 1 To 26
        Me.lstView.List(Me.lstView.ListCount - 1, i) = rngFind.Offset(0, i - 1).Text
    Next i
    End If
    Set rngFind = .FindNext(rngFind)
    Loop While Not rngFind Is Nothing And rngFind.Address <> strFirstFind
    End If
    End With
End Sub


This is how I load the listbox
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try replacing...

Code:
    With Me.lstView
         '.ListIndex = Application.Match(vLastName, Application.Index(.List, 0, 2), 0) - 1
    End With

with

Code:
    Dim i As Long    

    With Me.lstView
        For i = 0 To .ListCount - 1
            If .List(i, 1) = vLastName Then  '1 = 2nd column
                .ListIndex = i
                Exit For
            End If
        Next i
    End With

Although, I would suggest re-naming vLastName as sLastName to reflect the fact that it will store a string value.

Hope this helps!
 
Upvote 0
Try replacing...

Code:
    With Me.lstView
         '.ListIndex = Application.Match(vLastName, Application.Index(.List, 0, 2), 0) - 1
    End With

with

Code:
    Dim i As Long    

    With Me.lstView
        For i = 0 To .ListCount - 1
            If .List(i, 1) = vLastName Then  '1 = 2nd column
                .ListIndex = i
                Exit For
            End If
        Next i
    End With

Although, I would suggest re-naming vLastName as sLastName to reflect the fact that it will store a string value.

Hope this helps!


Problem solved. Thanks

I have one last request:

When I update a record, I will like to select it too in the listbox.

Here, since it will not be the last item, how do I get that selected?

The position of the data will not change. I will only add to the fields.

Regards
 
Upvote 0
That's great, glad it's working.

With regards to your next question, I don't know when I'll be available again. In any case, it's always best to start a new thread whenever you have a new question.

Cheers!
 
Upvote 0

Forum statistics

Threads
1,217,410
Messages
6,136,460
Members
450,013
Latest member
k4kamal

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top