Question Locked

Sort worksheets with in an Excel workbook

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

when i add a new worksheet to my Excel workbook my workbook will sort the worksheets ascending order automatically.

any features for this an Excel and any Macro code

3 replies

by thumbsup2

Are you asking if there is any way to get Excel to do that automatically?

If that is your question, I believe the answer is yes, sorta, kinda, well maybe. If you wrote a macro, it would need to know the name of the new sheet added and that's going to be different every time you add a new sheet. You can add that question to a macro. In addition, a new sheet will have no data TO be sorted, so nothing could be automatic upon first adding the sheet. If you paste something into a new sheet and then want to sort it, since a sort would require knowing the range of cells to be sorted you would need to build that question into your macro too. So, basically, there are so many variables that you would have to account for in a macro, it would be more work than simply highlighting the area to be sorted and clicking Data --> Sort, then choosing the columns to use for sort keys.

by nicolas.gillain

Hello,
I have just read your topic and I had the same problem one day ago. I don't know if a sorting based on sheet's name could help you but ... here is the VBA code :
With ThisWorkbook
For i = 1 To .Sheets.Count - 1
For j = i + 1 To .Sheets.Count
If .Sheets(i).Name < .Sheets(j).Name Then
Sheets(i).Move before:=Sheets(j)
Sheets(j).Move before:=Sheets(i)
End If
Next j
Next i
End With

I believe this code is as simple as possible but if you've some problem don't hesitate, i'll make effort to answer you

Ps: If comparison has to be case-sensitive, you can add the option : "Option Compare Text"
In same time if you could correct my grammatical/vocabulary mistakes, i'll be very grateful

This discussion is closed to new replies.