equivalent of getmonth??

Tron57

Board Regular
Joined
Sep 26, 2002
Messages
66
im not sure how to phrase this but there must be an eaiser way than what i have below.

sub Fill_months()

dim jan as string
dim feb as string
dim mar as string
'and soooo on
dim Month as byte

Month = Range("a1").value

jan = "January"
feb = "February"
mar = "March"
'and so on

if month = 1 then
range("A2").formula = jan
elseif month = 2 then
range("A2").formula = feb
elseif month = 3 then
range("a2").formula = mar



'and so on
end if

end sub


what i want is cell A2 string formula to be the value of A1 numeric value. and then cell a3 to be a string formula of A1 numeric value +1

for example

in cell A1= 3 user typs than then activates the macro
macro fills out

a2 = March
a3 = April
a4 = May

and so on.. there must be an easy way of doing this?? maybe an array, but im not sure how to do that...
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Could be done without a macro.

Put following in A2 and fill down :-

=TEXT(DATE(2003,A$1+ROW()-2,1),"mmmm")
 
Upvote 0
thats very cool... i learned from that one... it needs to be in the mod because the month will be contained/inerted in a string value.... ill figure somthing out. no worries thanks for that
 
Upvote 0
Use Select Case.
Code:
Sub getmonth()
    i = [A1]
    Select Case i
    Case 1
        [A2] = "JANUARY"
    Case 2
        [A2] = "FEBRUARY"
    Case 3
        [A2] = "MARCH"
    Case 4
        [A2] = "APRIL"
    Case 5
        [A2] = "MAY"
    Case 6
        [A2] = "JUNE"
    Case 7
        [A2] = "JULY"
    Case 8
        [A2] = "AUGUST"
    Case 9
        [A2] = "SEPTEMBER"
    Case 10
        [A2] = "OCTOBER"
    Case 11
        [A2] = "NOVEMBER"
    Case 12
        [A2] = "DECEMBER"
    Case Else
        [A2] = ""
    End Select
    [A2].AutoFill Destination:=Range("A2:A13"), Type:=xlFillSeries
End Sub
You could even turn this in to a function if you wanted to.
 
Upvote 0
If your cells are populated, you can efficiently stack a variant array. Otherwise, the following fires:

Code:
Sub test2()
Application.ScreenUpdating = False
With Range([b1], [a65536].End(3).Item(, 2))
    .FormulaR1C1 = "=TEXT(RC[-1]&""/1999"", ""mmmm"")"
    .Value = .Value
End With
Application.ScreenUpdating = True
End Sub
An implementation of: =TEXT(A1&"/1999", "mmmm")

Edit: I may have misread the question, this may be more on target:

Code:
Sub test2()
Application.ScreenUpdating = False
[a2] = [Text(A1&"/1999", "mmmm")]
[a2].AutoFill Destination:=Range([a2], [a65536].End(3)), Type:=xlFillSeries
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Just shooting rubber bands at the moon here, but you could put my {very simplistic} code in a Worksheet_Change event:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$1" Then
        i = [A1]
        Select Case i
        Case 1
            [A2] = "JANUARY"
        Case 2
            [A2] = "FEBRUARY"
        Case 3
            [A2] = "MARCH"
        Case 4
            [A2] = "APRIL"
        Case 5
            [A2] = "MAY"
        Case 6
            [A2] = "JUNE"
        Case 7
            [A2] = "JULY"
        Case 8
            [A2] = "AUGUST"
        Case 9
            [A2] = "SEPTEMBER"
        Case 10
            [A2] = "OCTOBER"
        Case 11
            [A2] = "NOVEMBER"
        Case 12
            [A2] = "DECEMBER"
        Case Else
            [A2] = ""
        End Select
        [A2].AutoFill Destination:=Range("A2:A13"), Type:=xlFillSeries
    End If
End Sub
...and when you type a number between 1 and 12 and hit Enter, boom, its done.

Not sure if this helps, but, there you go.
 
Upvote 0
Heres another option along the lines of Nates variant array suggestion.

Code:
Function MonthName(MonthVal)
'Enter month number to obtain month
Dim AllNames As Variant
    
AllNames = Array("January", "February", "March", _
        "April", "May", "June", "July", "August", _
        "September", "October", "November", "Decemeber")

MonthName = AllNames(MonthVal - 1)
End Function

Sub CallMonth()
'Put Month name in cell A2 based on A1's numerical value
Range("A2").Value = MonthName(Range("A1").Value)
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,495
Messages
6,113,992
Members
448,538
Latest member
alex78

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