Hi all,
Excel 2010 / windows 7
I'm trying to assign a value to the current month via 2 function then return it to a destination. I'm all new to function, so I keep getting the error as Invalide outside procedure.
First Function
to assign a number to the current month
Second function
To assign a month in letter to the current month
Then come the calling macro
I'm sure it's a easy thing to fix but I don't know.
If you've got a minute I would greatly appreciate.
Many thanks
Excel 2010 / windows 7
I'm trying to assign a value to the current month via 2 function then return it to a destination. I'm all new to function, so I keep getting the error as Invalide outside procedure.
First Function
to assign a number to the current month
Code:
Funtion Nmonths()
Dim Nmonth As String
If month = "2014-07" Then
Nmonth = "1"
ElseIf month = "2014-08" Then
Nmonth = "2"
ElseIf Format(Date, "yyyy-mm") = "2014-09" Then
Nmonth = "3"
ElseIf Format(Date, "yyyy-mm") = "2014-10" Then
Nmonth = "4"
ElseIf Format(Date, "yyyy-mm") = "2014-11" Then
Nmonth = "5"
ElseIf Format(Date, "yyyy-mm") = "2014-12" Then
Nmonth = "6"
ElseIf Format(Date, "yyyy-mm") = "2015-01" Then
Nmonth = "7"
ElseIf Format(Date, "yyyy-mm") = "2015-02" Then
Nmonth = "8"
ElseIf Format(Date, "yyyy-mm") = "2015-03" Then
Nmonth = "9"
ElseIf Format(Date, "yyyy-mm") = "2015-04" Then
Nmonth = "10"
ElseIf Format(Date, "yyyy-mm") = "2015-05" Then
Nmonth = "11"
ElseIf Format(Date, "yyyy-mm") = "2015-06" Then
Nmonth = "12"
End If
End Function
Second function
To assign a month in letter to the current month
Code:
Function Lmonth()
Dim Lmonth As String
If Format(Date, "yyyy-mm") = "2014-07" Then
Lmonth = "July"
ElseIf Format(Date, "yyyy-mm") = "2014-08" Then
Lmonth = "August"
ElseIf Format(Date, "yyyy-mm") = "2014-09" Then
Lmonth = "September"
ElseIf Format(Date, "yyyy-mm") = "2014-10" Then
Lmonth = "November"
ElseIf Format(Date, "yyyy-mm") = "2014-11" Then
Lmonth = "October"
ElseIf Format(Date, "yyyy-mm") = "2014-12" Then
Lmonth = "December"
ElseIf Format(Date, "yyyy-mm") = "2015-01" Then
Lmonth = "January"
ElseIf Format(Date, "yyyy-mm") = "2015-02" Then
Lmonth = "February"
ElseIf Format(Date, "yyyy-mm") = "2015-03" Then
Lmonth = "March"
ElseIf Format(Date, "yyyy-mm") = "2015-04" Then
Lmonth = "April"
ElseIf Format(Date, "yyyy-mm") = "2015-05" Then
Lmonth = "May"
ElseIf Format(Date, "yyyy-mm") = "2015-06" Then
Lmonth = "June"
End If
End Function
Then come the calling macro
Code:
Sub Definemonth()
Range("B3").FormulaR1C1 = Nmonth & ". " & Lmonth
End Sub
I'm sure it's a easy thing to fix but I don't know.
If you've got a minute I would greatly appreciate.
Many thanks