Hello. If I a have a bunch of tabs that are names of months, how can I order them by months. E.g. January, February, March, etc?
Hello. If I a have a bunch of tabs that are names of months, how can I order them by months. E.g. January, February, March, etc?
If you literally have just 12 tabs, 1 per month, then drag and drop will be the easiest way.
There is no built in sort function for tabs and to do it with vba would take longer to write the code than to sort them by hand (or mouse).
Oh ok. I have 60 tabs (5 years) so the dragging and dropping might take a little while. There has to be something out there. I'll keep looking on google. Thanks!!
How are the tab names formatted?
If the format is consistent, for example, January 2015 (i.e. full month name, single space, 4 digit year) then it could be coded.
Possibly it could be done with less consistent formats, need to give it a little thought.
I did have a quick look on google but nothing stood out as being readily available.
Yeah, the months are full names, the rest are just copies so, January (varying text) and then (1) (2) (3) for each year. Not sure if that makes sense....Basically each month is completely written out, and then has a space after it.
Can you type out a few examples so we don't wonder.
Varying text just leaves me guessing what you mean.
Can you just upload a workbook with those sheets?
Not sure if this is exactly what you're looking for, but give this a try:
![]()
Please Login or Register to view this content.
Thanks. Mr Clabullis. I'll take a look at this tomorrow. I'm on vacay![]()
@ Clabullis. I was trying to understand the code in your sheet but I wasn't sure what format it was "expecting". Was it something like this: Jan 4, Feb 3, Mar 2, Dec 1? I also wasn't able to follow certain pieces of the code. Please correct me where I'm wrong. You loop through years first and then months, right? What is "like" (I'm going to look this up)? I think the rest of it I get. It's looping from year 5 to year 1, and the last month in your array to the first month (Dec to Jan). Thanks!!
As clabulis appears to be offline, I'll answer on their behalf.
The code expects something like "Jan*(1)" where * represents any number of characters in the middle of the sheet name. This was based on your example format in post #5.
The code loops through the sheets, then months, then years, finding the latest sheet chronologically that matches the format,"Dec*(5)", then positioning it as the first sheet.
Next cycle of the loop, it finds the previous month, same year, "Nov*(5)", then positions that as the first sheet, with the "Dec*(5)" sheet being bumped down to second.
Process is repeated for each remaining sheet / month / year until "Jan*(1)" is pushed into first position, which should then have sorted the sheets in the correct order.
"Like" looks for a string that looks "Like" the sample that you are comparing to, with "Dec*(5)" as the string to compare, it looks for something that starts with "Dec", ends with "(5)" and has anything, from 0 to an unknown number of characters (represented using the "*" wildcard) in between.
Try
![]()
Please Login or Register to view this content.
@ Jason thanks. Makes sense.
@ jindon. I'll take a look at this code later today. Thanks!!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks