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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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,215,403
Messages
6,124,710
Members
449,182
Latest member
mrlanc20

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