Create variable month list in a column.

mopey12345

Board Regular
Joined
Nov 26, 2020
Messages
76
Office Version
  1. 2010
Platform
  1. Windows
Hi everyone,
I have to create a list of months 6 (min) up to 12 (max) using any month as the start month. Two cells define the start month and the number of months. Is there a better way than creating 84 arrays to cover all instances? eg JANMONTHNAMES6 = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun""), upto JANMONTHNAMES12= Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"), for each month. Thanks in advance.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi Mopey12345,

You've asked under Excel questions but I'm not aware of the Array() function so hope this helps:

Mopey12345.xlsx
ABC
1Start MonthNumber of MonthsList
2Jun9Jun
3Jul
4Aug
5Sep
6Oct
7Nov
8Dec
9Jan
10Feb
11 
12 
13 
Sheet1
Cell Formulas
RangeFormula
C2:C13C2=IF(ROW()-ROW($C$1)>$B$2,"",TEXT(DATE(2000,MATCH($A$2,{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"},0)+ROW()-ROW($C$1)-1,1),"mmm"))
 
Upvote 0
Why not just use a single array for all 12 months then use the month in the cell as a starting point to loop part of the array?

If you need it to cross the year end from Dec to Jan then use a 24 month array instead.

@Toadstool it's a vba question, not formula.
 
Upvote 0
Hi Mopey12345,

You've asked under Excel questions but I'm not aware of the Array() function so hope this helps:

Mopey12345.xlsx
ABC
1Start MonthNumber of MonthsList
2Jun9Jun
3Jul
4Aug
5Sep
6Oct
7Nov
8Dec
9Jan
10Feb
11 
12 
13 
Sheet1
Cell Formulas
RangeFormula
C2:C13C2=IF(ROW()-ROW($C$1)>$B$2,"",TEXT(DATE(2000,MATCH($A$2,{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"},0)+ROW()-ROW($C$1)-1,1),"mmm"))
Thank you.
 
Upvote 0
Why not just use a single array for all 12 months then use the month in the cell as a starting point to loop part of the array?

If you need it to cross the year end from Dec to Jan then use a 24 month array instead.

@Toadstool it's a vba question, not formula.
Thank you.
 
Upvote 0
There is no ideal answer to your question without knowing what the next steps are in the task. What will work for one thing might not always be as good for another.

If you decide to go with the formula based option that @Toadstool suggested then here are a couple of shorter alternatives. Note that neither of these will work if the date range rolls from December back to January. The formula in column E is for office 365 only but the one in column D will work with old versions as well.
Book1
ABCDE
2Feb9FebFeb
3MarMar
4AprApr
5MayMay
6JunJun
7JulJul
8AugAug
9SepSep
10OctOct
Sheet3
Cell Formulas
RangeFormula
E2:E10E2=TEXT(SEQUENCE(B2,,MONTH(A2&"0"))*29,"mmm")
D2:D10D2=IF(ROWS(D$2:D2)>B$2,"",TEXT((MONTH(A$2&"0")+ROWS(D$2:D2)-1)*29,"mmm"))
Dynamic array formulas.
 
Upvote 0
There is no ideal answer to your question without knowing what the next steps are in the task. What will work for one thing might not always be as good for another.

If you decide to go with the formula based option that @Toadstool suggested then here are a couple of shorter alternatives. Note that neither of these will work if the date range rolls from December back to January. The formula in column E is for office 365 only but the one in column D will work with old versions as well.
Book1
ABCDE
2Feb9FebFeb
3MarMar
4AprApr
5MayMay
6JunJun
7JulJul
8AugAug
9SepSep
10OctOct
Sheet3
Cell Formulas
RangeFormula
E2:E10E2=TEXT(SEQUENCE(B2,,MONTH(A2&"0"))*29,"mmm")
D2:D10D2=IF(ROWS(D$2:D2)>B$2,"",TEXT((MONTH(A$2&"0")+ROWS(D$2:D2)-1)*29,"mmm"))
Dynamic array formulas.
Thanks. The formula solution(s) work great to get us up an running but I am trying to learn vba, so was attempting to do it that way. Regards Phil
 
Upvote 0
There are probably more ways to do it with vba than there are with formulas. With vba the best method often depends what else you're going to do with the array afterwards.

If you're going to loop through it then a single fixed array with a defined start and end point would be the easiest way, if you want the array to only contain the required elements then you could look at writing the array on the fly. Not something that I use a lot of so I can never remember the correct code to use, if you wanted to look into it ReDim Preserve is the key to it.
 
Upvote 0
There are probably more ways to do it with vba than there are with formulas. With vba the best method often depends what else you're going to do with the array afterwards.

If you're going to loop through it then a single fixed array with a defined start and end point would be the easiest way, if you want the array to only contain the required elements then you could look at writing the array on the fly. Not something that I use a lot of so I can never remember the correct code to use, if you wanted to look into it ReDim Preserve is the key to it.
Thanks. At my level the single fixed array with a defined start and end point would be way I will try. Thanks again for the help. Appreciated.
 
Upvote 0
I've got this but seems a lot of code.
If Worksheets("Sheet1").Range("C3") = "Jan" And Worksheets("Sheet1").Range("C4") = "6" Then
Worksheets("Sheet1").Range("D3") = "Jan"
Worksheets("Sheet1").Range("D4") = "Feb"
Worksheets("Sheet1").Range("D5") = "Mar"
Worksheets("Sheet1").Range("D6") = "Apr"
Worksheets("Sheet1").Range("D7") = "May"
Worksheets("Sheet1").Range("D8") = "Jun"
ElseIf Worksheets("Sheet1").Range("C3") = "Jan" And Worksheets("Sheet1").Range("C4") = "7" Then
Worksheets("Sheet1").Range("D3") = "Jan"
Worksheets("Sheet1").Range("D4") = "Feb"
Worksheets("Sheet1").Range("D5") = "Mar"
Worksheets("Sheet1").Range("D6") = "Apr"
Worksheets("Sheet1").Range("D7") = "May"
Worksheets("Sheet1").Range("D8") = "Jun"
Worksheets("Sheet1").Range("D9") = "Jul"
ElseIf Worksheets("Sheet1").Range("C3") = "Jan" And Worksheets("Sheet1").Range("C4") = "8" Then
Worksheets("Sheet1").Range("D3") = "Jan"
Worksheets("Sheet1").Range("D4") = "Feb"
Worksheets("Sheet1").Range("D5") = "Mar"
Worksheets("Sheet1").Range("D6") = "Apr"
Worksheets("Sheet1").Range("D7") = "May"
Worksheets("Sheet1").Range("D8") = "Jun"
Worksheets("Sheet1").Range("D9") = "Jul"
Worksheets("Sheet1").Range("D10") = "Aug"
ElseIf Worksheets("Sheet1").Range("C3") = "Jan" And Worksheets("Sheet1").Range("C4") = "9" Then
Worksheets("Sheet1").Range("D3") = "Jan"
Worksheets("Sheet1").Range("D4") = "Feb"
Worksheets("Sheet1").Range("D5") = "Mar"
Worksheets("Sheet1").Range("D6") = "Apr"
Worksheets("Sheet1").Range("D7") = "May"
Worksheets("Sheet1").Range("D8") = "Jun"
Worksheets("Sheet1").Range("D9") = "Jul"
Worksheets("Sheet1").Range("D10") = "Aug"
Worksheets("Sheet1").Range("D11") = "Sep"
ElseIf Worksheets("Sheet1").Range("C3") = "Jan" And Worksheets("Sheet1").Range("C4") = "10" Then
Worksheets("Sheet1").Range("D3") = "Jan"
Worksheets("Sheet1").Range("D4") = "Feb"
Worksheets("Sheet1").Range("D5") = "Mar"
Worksheets("Sheet1").Range("D6") = "Apr"
Worksheets("Sheet1").Range("D7") = "May"
Worksheets("Sheet1").Range("D8") = "Jun"
Worksheets("Sheet1").Range("D9") = "Jul"
Worksheets("Sheet1").Range("D10") = "Aug"
Worksheets("Sheet1").Range("D11") = "Sep"
Worksheets("Sheet1").Range("D12") = "Oct"
ElseIf Worksheets("Sheet1").Range("C3") = "Jan" And Worksheets("Sheet1").Range("C4") = "11" Then
Worksheets("Sheet1").Range("D3") = "Jan"
Worksheets("Sheet1").Range("D4") = "Feb"
Worksheets("Sheet1").Range("D5") = "Mar"
Worksheets("Sheet1").Range("D6") = "Apr"
Worksheets("Sheet1").Range("D7") = "May"
Worksheets("Sheet1").Range("D8") = "Jun"
Worksheets("Sheet1").Range("D9") = "Jul"
Worksheets("Sheet1").Range("D10") = "Aug"
Worksheets("Sheet1").Range("D11") = "Sep"
Worksheets("Sheet1").Range("D12") = "Oct"
Worksheets("Sheet1").Range("D13") = "Nov"
ElseIf Worksheets("Sheet1").Range("C3") = "Jan" And Worksheets("Sheet1").Range("C4") = "12" Then
Worksheets("Sheet1").Range("D3") = "Jan"
Worksheets("Sheet1").Range("D4") = "Feb"
Worksheets("Sheet1").Range("D5") = "Mar"
Worksheets("Sheet1").Range("D6") = "Apr"
Worksheets("Sheet1").Range("D7") = "May"
Worksheets("Sheet1").Range("D8") = "Jun"
Worksheets("Sheet1").Range("D9") = "Jul"
Worksheets("Sheet1").Range("D10") = "Aug"
Worksheets("Sheet1").Range("D11") = "Sep"
Worksheets("Sheet1").Range("D12") = "Oct"
Worksheets("Sheet1").Range("D13") = "Nov"
Worksheets("Sheet1").Range("D14") = "Dec"

Need to replicate this for all the other months.
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,461
Members
449,085
Latest member
ExcelError

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