View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Luke M Luke M is offline
external usenet poster
 
Posts: 2,722
Default Macro - insert slashes into a cell

Sub MakeDate()
Dim xYear, xMonth, xDay As Double
With ActiveCell
xYear = Left(.Value, 4)
xMonth = Mid(.Value, 5, 2)
xDay = Right(.Value, 2)
'Combine and spit out new value
..Value = xYear & "/" & xMonth & "/" & xDay
..NumberFormat = "yyyy/mm/dd"
End With
End Sub
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Cookshack" wrote:

I'm having trouble recording a macro that will insert slashes into a cell
that already has data in it.

For example, a cell contains the following data "20080723" and I want to
create a macro, using "relative references" that will insert slashes as
follows "2008/07/23." In other words, I want the macro to create the slashes
in that location in the cell regardless of what is in the cell. For example,
if the cell contains 20061103, I want the end result to be 2006/11/03.
However, when I run the macro, I still get 2008/07/03, regardless of what is
in the cell.

Can anyone help me?