Macro - insert slashes into a cell

C

Cookshack

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?
 
L

Luke M

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
 

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

Top