Months as Column Headings

E

Exceller

I would love have a script that enters the months of the year as column
headings. I would like it to enter "January", through "December" (all 12
months) beginning in the cell I select. So, If I select cell "B4" and run
the script, then "January" will be entered in B4, "February" will be entered
in cell C4, "March" in D4, and so on, through December.

Thanks.
 
B

Bernard Liengme

Sub tryme()
mymonths = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec")
myrow = Selection.Row
mycol = Selection.Column
For j = 0 To 11
Cells(myrow, mycol) = mymonths(j)
mycol = mycol + 1
Next j
End Sub

I was too lazy to type full month names!
best wishes
 
M

Mike H

Hi,

Alt +F11 to open Vb editor, right click 'This Workbook' and insert module
and paste the code below in.

Sub sonic()
ActiveCell.Value = "January"
Selection.AutoFill Destination:=Range(ActiveCell.Address & ":" _
& ActiveCell.Offset(, 11).Address), Type:=xlFillDefault
End Sub

Mike
 
P

Patrick Molloy

Function Months()
Dim i As Long
Dim m(1 To 12) As String
For i = 1 To 12
m(i) = Format((DateSerial(2008, i, 1)), "MMMM")
Next
Months = m

End Function

select 12 cells in a row and enter =Months() as an array formula
 
J

Jim Cone

Use a custom list instead.
--
Jim Cone
Portland, Oregon USA



"Exceller"
wrote in message
I would love have a script that enters the months of the year as column
headings. I would like it to enter "January", through "December" (all 12
months) beginning in the cell I select. So, If I select cell "B4" and run
the script, then "January" will be entered in B4, "February" will be entered
in cell C4, "March" in D4, and so on, through December.

Thanks.
 
E

Exceller

It works perfectly--thanks. I forgot one thing...in the cell to the right of
"December" input "Full Year". Could you please show me how to put that into
the script? Thanks.
 
M

Mike H

Will this do?

Sub sonic()
ActiveCell.Value = "January"
Selection.AutoFill Destination:=Range(ActiveCell.Address & ":" _
& ActiveCell.Offset(, 11).Address), Type:=xlFillDefault
ActiveCell.Offset(, 12).Value = "Full Year"
End Sub

Mike
 
R

Rick Rothstein

This is a slimmer version of your code...

Sub sonic()
With ActiveCell
.Value = "January"
.AutoFill Destination:=.Resize(1, 12)
.Offset(, 12).Value = "Full Year"
End With
End Sub
 
E

Exceller

How can I take this script that you wrote and add the following instructions
to it. Here's your code:

Sub sonic()
With ActiveCell
.Value = "January"
.AutoFill Destination:=.Resize(1, 12)
.Offset(, 12).Value = "Full Year"
End With
End Sub

What I'd like to do is actually make that the second instruction. The code
that I would like added takes the value in the ActiveCell and copies it
rightward to the next 11 adjacent cells and adds "Full Year" in the last
adjacent cell. After that is completed THEN the instructions above kick in.

So, if I enter "2009 Budget" into cell B5 and execute the macro "2009
Budget" (or whatever the value is in that cell) will be copied across the
next 11 adjacent cells and "Full Year" would be added at the end, THEN the
script above executes, adding "January" into the cell ABOVE the ActiveCell
(B4) and then autofills those adjacent cells and puts "Full Year" at the end.

Thanks.
 
R

Rick Rothstein

Does this do what you want?

Sub sonic()
With ActiveCell
.Offset(-1).Value = "January"
.Offset(-1).AutoFill Destination:=.Offset(-1).Resize(1, 12)
.Resize(1, 12).Value = .Value
.Offset(-1, 12).Resize(2, 1).Value = "Full Year"
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top