+ Reply to Thread
Results 1 to 7 of 7

Scrolling listbox to show last entered item

  1. #1
    Forum Contributor
    Join Date
    07-23-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    211

    Scrolling listbox to show last entered item

    Hi

    Can anyone advise on a problem I have with regard to list boxes?

    I have a userform which shows a listbox. This listbox is populated when I hit a command button. The problem is that the listbox shows 8 rows of items. When I reach the 9th row, I can't see the last inputted entries. I have linked the listbox to rowsource properties via a named range. To ensure that I capture everything, I have set the range to cover every row (by the way there are 3 columns).

    Is there a way to view the last entered data? When I used :

    Me.ListBox1.ListIndex = ListBox1.ListCount - 1

    it scrolled to the bottom (obviously!)

    Maybe .AddItem could be the way here?

    Thanks

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Scrolling listbox to show last entered item

    It's unclear whether using that syntax displays the 9th row or not.

    Can you see the last row after scrolling?
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    07-23-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    211

    Re: Scrolling listbox to show last entered item

    Hi Andy

    What I should have said is that it scrolled to the 998th row! That is probably because I set the range as $A$3:$D$999. I don't want to reduce the $999 because I won't know how many rows of information will be inputted by the user but think it will be less that 999. When the 9th item is inputted, I have to use the listbox scroll button to view it because only the first 8 items are shown in the listbox. What I want to do is that when the 9th item is inputted, it should scroll down one to show the 9th row and keep scrolling down to display the last row entered rather than manually having to scroll down.
    Cheers

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Scrolling listbox to show last entered item

    Firstly you should be able to restrict the rowsource range to only those cells that contain data.
    Something like this in the initialize event of the userform

    Please Login or Register  to view this content.
    You can use TopIndex property of the Listbox to control what row is at the top of the listbox.

  5. #5
    Forum Contributor
    Join Date
    07-23-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    211

    Re: Scrolling listbox to show last entered item

    Simple as that, Andy! It worked a treat.

    Thanks very much.

  6. #6
    Forum Contributor
    Join Date
    07-23-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    211

    Re: Scrolling listbox to show last entered item

    Andy

    I had a little problem after. Whilst your macro worked a treat, it did so when I had the worksheet selected where the data was written. How could I amend your code so that it will do the selection for rowsource property when another worksheet is selected?

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Scrolling listbox to show last entered item

    try this

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1