Consulting

Results 1 to 12 of 12

Thread: Putting the worksheets in order...

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Contributor Daxton A.'s Avatar
    Joined
    Jun 2004
    Location
    Biloxi, Mississippi
    Posts
    143
    Location

    Question Putting the worksheets in order...

    ok what this is is a excel file that I made to keep up with @ work. Like if I have something to do I don't want to forget it the next day and its also a workbook that I have other things in for myself in case I need it in the future.
    I made a FindSheet macro that pops up all the sheets in a listbox and its pretty much working. I'm just trying to get the worksheets to change in what order there in in the list box. I'll take a pic of it so you know what I'm talking about for sure. What it does is take whatever the .Listboxes order is and puts the worksheets in that order when the button is pressed. Well I keep getting an error with my code and I was wondering if anyone out there new what it was supposed to say. I think the problem is that where it says:
    "sheet2 = UCase(Sheets(i + 1).Name)" the problem is that "i + 1". If there is say 15 worksheets its trying to go to 16. I'm sure there's something in here that I didn't type so don't be afraid to ask me any questions.


    Private Sub cmdPoolThem_Click()
    Dim flag As Integer Dim i As Integer 
    Dim temp As String 
    Dim sheet1 As String 
    Dim sheet2 As String 
    For i = 1 To (Sheets.Count) 
        sheet1 = UCase(Sheets(i).Name) 
        sheet2 = UCase(Sheets(i + 1).Name) 
        If sheet1 < sheet2 Then 
            Sheets(i).Move after:=Sheets(i + 1) 
            theFlag = 1 
        End If 
        'letterNumberer1(sheet1) 
        'letterNumberer2(sheet2) 
    Next i 
    Do flag = 0 
        For i = 1 To lstPool.ListCount - 1 
            If UCase(lstPool.List(i, 0)) < UCase(lstPool.List(i - 1, 0)) Then 
                temp = lstPool.List(i, 0) 
                lstPool.List(i, 0) = lstPool.List(i - 1, 0) 
                lstPool.List(i - 1, 0) = temp 
                flag = 1 
            End If 
        Next i 
    Loop Until flag = 0
    End Sub
    Last edited by Aussiebear; 04-29-2023 at 07:49 PM. Reason: Adjusted the code tags

Posting Permissions

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