Populate cells with array

zJenkins

Board Regular
Joined
Jun 5, 2015
Messages
148
I have a macro that populates a range of cells with the months horizontally, but am getting an error when I try to make it vertical.

Horizontal:
Code:
ActiveCell.Resize(, 12) = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

Vertical:
Code:
ActiveCell.Resize(12, ) = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

It looks like it has something to do with the (12, )

Any help would be great. Thanks!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try:
Code:
ActiveCell.Resize(12) = Application.Transpose(Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))
 
Upvote 0
Nevermind, found a solution.

Thanks

Code:
ActiveCell.Resize(12, 1) = Application.Transpose(Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))
 
Upvote 0
Try:
Code:
ActiveCell.Resize(12) = Application.Transpose(Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))

Thanks Akuini...didn't see that you had responded. I appreciate your time
 
Upvote 0
You cannot have a blank or zero in the Resize property... either put a 1 after the comma or omit the comma (doing that will make the columns argument the default of 1). Of course, after you fix that, your code will not place the month name abbreviation downward... you need to Transpose the array to place it vertically...
Code:
ActiveCell.Resize(12) = Application.Transpose(Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))
There is a "simpler" code line that will do the same thing as the above...
Code:
ActiveCell.Resize(12) = [IF({1},TEXT(28*ROW(1:12),"mmm"))]
 
Upvote 0
There is a "simpler" code line that will do the same thing as the above...
Code:
ActiveCell.Resize(12) = [IF({1},TEXT(28*ROW(1:12),"mmm"))]
How does it work?
(I note it doesn't work if over 12 rows.)

For a simple to understand code for any start month and any number of rows:
Code:
With ActiveCell
    .Value = "Jan"
    .AutoFill Destination:=.Resize(12)
End With
 
Last edited:
Upvote 0
This should work for any number of rows:
Code:
ActiveCell.Resize(12) = [TEXT(Date(1900,ROW(1:12),1),"mmm")]
 
Upvote 0
I understand the Text(28*row(1:12),"mmm", this is where the month text comes form, but how does the "If{1}" work?
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,178
Members
448,871
Latest member
hengshankouniuniu

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