Sorting Worksheets

cuetipper

Board Regular
Joined
Nov 9, 2018
Messages
67
Would it be possible to loop thuru all the worksheets , counting how many rows are used in colum A, and move the position of the worksheets so the ones with the highest @ of entries are on the left , diminishing to the right?
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try this macro:
Code:
Public Sub Sort_Worksheets()
    
    Dim i As Long, j As Long
    
    With ThisWorkbook
        For i = 1 To .Worksheets.Count
            For j = 1 To .Worksheets.Count - 1
                If .Worksheets(j).Cells(Rows.Count, 1).End(xlUp).Row < .Worksheets(j + 1).Cells(Rows.Count, 1).End(xlUp).Row Then
                    .Worksheets(j).Move After:=.Worksheets(j + 1)
                End If
            Next
        Next
    End With
    
End Sub
 
Last edited:
Upvote 0
Are you running it on the workbook in which the code resides or on another workbook? If the latter try changing ThisWorkbook to ActiveWorkbook.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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