Instructions within VBA Functions

  • Thread starter Thread starter silvest
  • Start date Start date
S

silvest

I defined a function in VBA that converts dates keyed in as YYYYMMDD t
be displayed as DD/MM/YYYY using "DateValue" command as well as th
Left, Mid and Right functions

However, excel will only display the dates in the serial numbers.

After the conversion into serial numbers (before 'end function'), i ha
this:

*ActiveCell.Select
Selection.NumberFormat = "dd/mm/yyyy"*

But somehow, it doesn't select that cell to convert into dd/mm/yyy
format.
I have to manually right click the cell and format it as date.

Is there anyway to do this in VBA
 
Hi Silvest,

Not in a function; a function can not change anything in a worksheet. It can
only return a value to the position from which it was called (replace the
call with a value).
You can do what you require in a macro, or you can construct a function
which returns the date as a string. Of course the function call will need an
extra cell.

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel
 
The only reason the approach you show would not work (given that the cell to
be selected is in the activewindow) that I can think of is if your date
serial is being stored as a string rather than a number.
 

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

Back
Top