Populate cells with array

zJenkins

Board Regular
Joined
Jun 5, 2015
Messages
144
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!
 

Akuini

Well-known Member
Joined
Feb 1, 2016
Messages
2,359
Office Version
2013
Platform
Windows
Try:
Code:
ActiveCell.Resize(12) = Application.Transpose(Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))
 

zJenkins

Board Regular
Joined
Jun 5, 2015
Messages
144
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"))
 

zJenkins

Board Regular
Joined
Jun 5, 2015
Messages
144
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
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
35,504
Office Version
2010
Platform
Windows
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"))]
 

footoo

Well-known Member
Joined
Sep 21, 2016
Messages
2,660
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:

footoo

Well-known Member
Joined
Sep 21, 2016
Messages
2,660
This should work for any number of rows:
Code:
ActiveCell.Resize(12) = [TEXT(Date(1900,ROW(1:12),1),"mmm")]
 

zJenkins

Board Regular
Joined
Jun 5, 2015
Messages
144
I understand the Text(28*row(1:12),"mmm", this is where the month text comes form, but how does the "If{1}" work?
 

Forum statistics

Threads
1,081,975
Messages
5,362,510
Members
400,678
Latest member
alecalec202

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top