+ Reply to Thread
Results 1 to 9 of 9

Adding a previous and next button with a List Box

  1. #1
    Registered User
    Join Date
    03-26-2022
    Location
    USA
    MS-Off Ver
    360
    Posts
    4

    Adding a previous and next button with a List Box

    I am using a list box with two buttons. One button is to move down the list the other is to move up it. I am able to do this by changing the value of the cell link using vba code:
    If Range("S6").value >1 then Range("S6").value = Range("S6").value - 1

    This code works great to change the selection the problem is the list box does not scroll with the selection. I have tried using the TopIndex property of the ListBox but I can't figure out how to actually control the list box. I keep getting "object doesn't support this property or method" Error. Here is the code:

    Sub PreviousButton_Click()
    Dim CategoryListBox as Object

    Set CategoryListBox = worksheets("Screened List").Shapes("List Box 2")
    CategoryListBox.TopIndex = CategoryListBox.ListIndex
    If Range("S6").value >1 then Range("S6").value = Range("S6").value - 1
    End Sub
    Last edited by redlinefx18; 03-26-2022 at 11:14 AM. Reason: clarification

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,303

    Re: Adding a previous and next button with a List Box

    see big yellow banner - how to upload your workbook.
    far easier to give advice if able to see actual app. as none of the code makes sense.
    is your listbox embedded on the page or are you using a UserForm
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

  3. #3
    Registered User
    Join Date
    03-26-2022
    Location
    USA
    MS-Off Ver
    360
    Posts
    4

    Re: Adding a previous and next button with a List Box

    Ok I attached an example of what I am trying to do.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    03-26-2022
    Location
    USA
    MS-Off Ver
    360
    Posts
    4

    Re: Adding a previous and next button with a List Box

    Quote Originally Posted by torachan View Post
    see big yellow banner - how to upload your workbook.
    far easier to give advice if able to see actual app. as none of the code makes sense.
    is your listbox embedded on the page or are you using a UserForm
    Torachan, any thoughts on this?

  5. #5
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,303

    Re: Adding a previous and next button with a List Box

    Best I can do - sorry unable to move down list after reaching last visible row.
    Try using 'ActiveX' control.

    Please Login or Register  to view this content.

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Adding a previous and next button with a List Box

    Make use of an Active X Control Listbox and then Scroll Option is available...
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  7. #7
    Registered User
    Join Date
    03-26-2022
    Location
    USA
    MS-Off Ver
    360
    Posts
    4

    Re: Adding a previous and next button with a List Box

    Thanks guys for your help. Using an ActiveX Listbox worked perfectly. I did modify the code a little so that it would work the same as if you were to use the up and down arrow. I figured I would post the code I used just in case someone wants to do something similar.

    Please Login or Register  to view this content.

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Adding a previous and next button with a List Box

    Glad to have helped...Tx for rep +

  9. #9
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,303

    Re: Adding a previous and next button with a List Box

    thanks for the feedback and rep pt.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How to insert Previous, Next Button & Print Record Button in excel???
    By vijubhau in forum Excel General
    Replies: 3
    Last Post: 10-24-2018, 07:01 AM
  2. [SOLVED] Previous Sheet(s) button
    By PFDave in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-09-2016, 08:03 AM
  3. [SOLVED] Adding a last row in a range adding the previous!
    By apla in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-19-2013, 09:19 AM
  4. Next & Previous buttons not working when adding Last button
    By jlsewall in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-10-2013, 09:41 AM
  5. Help me to code next and previous button
    By vijaynadiad in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-01-2013, 02:03 PM
  6. button previous to go to previous
    By akhtar151 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-03-2007, 11:40 AM
  7. Previous & Next button
    By tian0020 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-03-2007, 01:59 AM

Tags for this Thread

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