• Format a cell with a custom function (Excel 2000 SP-3)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Format a cell with a custom function (Excel 2000 SP-3)

    Author
    Topic
    #437595

    I wrote a function to convert dates from yyyymmdd format to a numeric date (20061128 => 39049) but in addition to creating the date number I want the cell formatting changed to mm/dd/yy. Is there any way to do this automatically from within the function?

    Function DateConv(DATE8N) As Date

    Dim TextDate As String
    TextDate = Mid(DATE8N, 5, 2) & “/” & Right(DATE8N, 2) & “/” & Left(DATE8N, 4)
    DateConv = CDate(TextDate)

    End Function

    Viewing 1 reply thread
    Author
    Replies
    • #1040815

      No, a user-defined function can only return a value, it cannot modify a cell in any other way. Any code intented to do that will simply be ignored. You’ll have to change the format manually, or write a macro to do so.

    • #1041186

      Hi David
      Try the attached workbook. In addition to what you can see there is a hidden sheet which holds a named range. As well, there is code in the workbook.
      You should be able to set up the appropriate named range, and also copy the various procedures to your workbook.

      • #1041211

        Interesting solution, but a bit of an overkill for how I would be using the formula. I am intrigued with your ThisWorkbook subs – I’m sure I’ll find a use for them somewhere.

    Viewing 1 reply thread
    Reply To: Format a cell with a custom function (Excel 2000 SP-3)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: