VBA sort sheets depending of the number of rows used

Leske

Active Member
Joined
Aug 26, 2008
Messages
297
Hi,

I was wondering if there was an easy code to use to sort my sheets based on the used rows.

So i have several sheets over the 100 and i would like to see them from the biggest line items to the smallest line items.

Suggestions?

Kind regards,

Les
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Try this:-
The code assumes that the row counts in each sheet is different !!!!

Code:
[COLOR=navy]Sub[/COLOR] MG18Jul42
[COLOR=navy]Dim[/COLOR] shtcnt [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] sht [COLOR=navy]As[/COLOR] Worksheet, c [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] n [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
shtcnt = Worksheets.Count
[COLOR=navy]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] sht [COLOR=navy]In[/COLOR] Worksheets
    .Item(sht.UsedRange.Rows.Count) = sht.Name
[COLOR=navy]Next[/COLOR] sht
Application.ScreenUpdating = False
[COLOR=navy]For[/COLOR] n = 1 To shtcnt
      Sheets(.Item(Application.Large(.keys, n))).Move _
      after:=Sheets(Sheets.Count) 
[COLOR=navy]Next[/COLOR] n
Application.ScreenUpdating = True
[COLOR=navy]End[/COLOR] [COLOR=navy]With[/COLOR]
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0
In that case, he will have to decide how he wants his sheets sorted and ask if the code can be altered to take care of that situation !!
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,580
Members
448,972
Latest member
Shantanu2024

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