ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro - insert slashes into a cell (https://www.excelbanter.com/excel-discussion-misc-queries/256314-macro-insert-slashes-into-cell.html)

Cookshack

Macro - insert slashes into a cell
 
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?

Luke M

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?



All times are GMT +1. The time now is 06:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com