xluser2007
07-19-2008, 01:43 AM
Hi All,
I am trying to make a simple UDF that takes a date e.g. 31/12/2007 or 10/12/2007 and converts it to "Dec07" String i.e. "mmmyy" format on the date.
I tried it as follows:
Public Sub Convert_date_to_string(mrng_input_dte As Range)
Dim mdte_input As Date 'This is the input date, whcih we will convert to a string
Dim mStr_output_date As String
' Convert input range value to a date
mdte_input = CDate(mrng_input_dte.Value)
' Convert input date to string e.g 31/12/2007 to "Dec07"
mStr_output_date = CStr(Format(mdte_input, "mmmyy"))
Debug.Print mStr_output_date
End Sub
Then I tried testing as follows:
Sub test()
Call Convert_date_to_string(ThisWorkbook.Range("previous_val_date"))
End Sub
The "test" routine gave an error:
"Compile error: Method or data member not found"
and highlights "Range" in the routine.
Please note that I have defined "previous_val_date" as a global named range ( a date value of 31/12/2007).
Could anyone please explain why the above isn't working?
regards,
I am trying to make a simple UDF that takes a date e.g. 31/12/2007 or 10/12/2007 and converts it to "Dec07" String i.e. "mmmyy" format on the date.
I tried it as follows:
Public Sub Convert_date_to_string(mrng_input_dte As Range)
Dim mdte_input As Date 'This is the input date, whcih we will convert to a string
Dim mStr_output_date As String
' Convert input range value to a date
mdte_input = CDate(mrng_input_dte.Value)
' Convert input date to string e.g 31/12/2007 to "Dec07"
mStr_output_date = CStr(Format(mdte_input, "mmmyy"))
Debug.Print mStr_output_date
End Sub
Then I tried testing as follows:
Sub test()
Call Convert_date_to_string(ThisWorkbook.Range("previous_val_date"))
End Sub
The "test" routine gave an error:
"Compile error: Method or data member not found"
and highlights "Range" in the routine.
Please note that I have defined "previous_val_date" as a global named range ( a date value of 31/12/2007).
Could anyone please explain why the above isn't working?
regards,