开发者

Excel VBA alternative way of sorting by date

开发者 https://www.devze.com 2023-01-09 19:42 出处:网络
I\'m currently working on a document which has about 25 columns, each headed by a date. Now I have to sort these columns by date. However, the sorting should not start with January and run until Decem

I'm currently working on a document which has about 25 columns, each headed by a date. Now I have to sort these columns by date. However, the sorting should not start with January and run until December. In my document, the sorting should start with September, and run until June (July and August can be omitted, as my document relates to a schoolyear, which runs from September to June in Belgium).

Is there anyone who ca开发者_Python百科n help me with the code for this kind of sorting? I first select the required range, and then use Selection.Sort, but then it always sorts starting with January.

Many thanks in advance!

Kind regards, Marc


Say, you have the month number from 1 to 12 in row 1. Add a helper row, containing the formula

=MOD(A1-8+12,12), =MOD(B1-8+12,12), ...

(add the formula in the first cell and drag it to the right; "8" is for "September")

Sort the columns by this value.

0

精彩评论

暂无评论...
验证码 换一张
取 消