+ Reply to Thread
Results 1 to 3 of 3

Listbox with Worksheets List to display in reverse order

  1. #1
    Registered User
    Join Date
    12-17-2014
    Location
    London, UK
    MS-Off Ver
    2016
    Posts
    54

    Listbox with Worksheets List to display in reverse order

    Hi all,

    i have the code below which displays the list correctly but i want it in reverse order i.e. from Right to Left if possible?

    VBA Code:
    Private Sub CommandButton2_Click()

    Dim i As Integer, sht As String
    Dim ws As Worksheet

    'Show/Go to selected worksheet'
    For i = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(i) = True Then
    sht = ListBox1.List(i)
    End If
    Next i
    Sheets(sht).Activate
    ActiveSheet.Visible = xlSheetVisible
    ActiveWindow.DisplayGridlines = False
    Range("D5").Activate

    'Hide all other sheets.'
    For Each ws In Worksheets
    If ws.Name <> ActiveSheet.Name Then
    ws.Visible = xlSheetHidden
    End If
    Next ws

    Unload Me
    End Sub

    Private Sub UserForm_Initialize()
    Dim N As Long
    'the n=3 hides the 1st sheet!'
    For N = 3 To ActiveWorkbook.Sheets.Count
    ListBox1.AddItem ActiveWorkbook.Sheets(N).Name
    Next N
    ListBox1.ListIndex = 0
    End Sub

    END OF CODE.

    any help appreciated.

    thanks in advance.

    Al

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

    Re: Listbox with Worksheets List to display in reverse order

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

    use reverse loop, similar to loop in other section of your code.

    Please Login or Register  to view this content.
    or add to top of listbox
    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    12-17-2014
    Location
    London, UK
    MS-Off Ver
    2016
    Posts
    54

    Re: Listbox with Worksheets List to display in reverse order

    Thanks Andy and apologies.

    here is the code again. hopefully the right way?

    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)

Similar Threads

  1. [SOLVED] Reverse Worksheets Order
    By Ibro Vehabovic in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-17-2016, 08:01 AM
  2. Combobox date list - reverse display order
    By Lyric in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-24-2011, 04:47 PM
  3. Display COUNTIF results in reverse order
    By kn427 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-19-2008, 10:36 AM
  4. Cell Reference to Display Data in Reverse Order?
    By awhinston in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-15-2007, 01:19 PM
  5. ListBox items paste into worksheet in reverse order
    By Casey in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-26-2006, 01:19 PM

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