#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default macro to replace

Hi, in column "A" i have dates. (01.12.2010 ; 02.12.2010 ; 03.12.2010....) I
need to replace only the year.

01.12.2010 01.12.2009
02.12.2010 02.12.2009
03.12.2010 02.12.2009
.......

Can a macro replace only the year?
Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default macro to replace

--Use Find/Replace dialog to replace 2010 with 2009

--OR use a formula in cell B1 and copy down
=DATE(2009,MONTH(A1),DAY(A1))

--OR if you are looking for a macro then try

Sub Macro()
Dim cell As Range
For Each cell In Selection
cell.Value = DateAdd("yyyy", -1, cell)
Next
End Sub

--
Jacob


"puiuluipui" wrote:

Hi, in column "A" i have dates. (01.12.2010 ; 02.12.2010 ; 03.12.2010....) I
need to replace only the year.

01.12.2010 01.12.2009
02.12.2010 02.12.2009
03.12.2010 02.12.2009
......

Can a macro replace only the year?
Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default macro to replace

Hi Jacob, it's working, but i have to select all cells with date in column A.
Can a macro do this? I need a macro to select in column A, all cells with
date from A2 to tha last cell with date.
Can this be done?
Thanks

"Jacob Skaria" a scris:

--Use Find/Replace dialog to replace 2010 with 2009

--OR use a formula in cell B1 and copy down
=DATE(2009,MONTH(A1),DAY(A1))

--OR if you are looking for a macro then try

Sub Macro()
Dim cell As Range
For Each cell In Selection
cell.Value = DateAdd("yyyy", -1, cell)
Next
End Sub

--
Jacob


"puiuluipui" wrote:

Hi, in column "A" i have dates. (01.12.2010 ; 02.12.2010 ; 03.12.2010....) I
need to replace only the year.

01.12.2010 01.12.2009
02.12.2010 02.12.2009
03.12.2010 02.12.2009
......

Can a macro replace only the year?
Thanks!

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default macro to replace

Try

Dim cell As Range, rngData As Range

Set rngData = Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row)
For Each cell In rngData
If IsDate(cell) Then cell.Value = DateAdd("yyyy", -1, cell)
Next

--
Jacob


"puiuluipui" wrote:

Hi Jacob, it's working, but i have to select all cells with date in column A.
Can a macro do this? I need a macro to select in column A, all cells with
date from A2 to tha last cell with date.
Can this be done?
Thanks

"Jacob Skaria" a scris:

--Use Find/Replace dialog to replace 2010 with 2009

--OR use a formula in cell B1 and copy down
=DATE(2009,MONTH(A1),DAY(A1))

--OR if you are looking for a macro then try

Sub Macro()
Dim cell As Range
For Each cell In Selection
cell.Value = DateAdd("yyyy", -1, cell)
Next
End Sub

--
Jacob


"puiuluipui" wrote:

Hi, in column "A" i have dates. (01.12.2010 ; 02.12.2010 ; 03.12.2010....) I
need to replace only the year.

01.12.2010 01.12.2009
02.12.2010 02.12.2009
03.12.2010 02.12.2009
......

Can a macro replace only the year?
Thanks!

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default macro to replace

It's perfect!
Thanks allot!

"Jacob Skaria" a scris:

Try

Dim cell As Range, rngData As Range

Set rngData = Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row)
For Each cell In rngData
If IsDate(cell) Then cell.Value = DateAdd("yyyy", -1, cell)
Next

--
Jacob


"puiuluipui" wrote:

Hi Jacob, it's working, but i have to select all cells with date in column A.
Can a macro do this? I need a macro to select in column A, all cells with
date from A2 to tha last cell with date.
Can this be done?
Thanks

"Jacob Skaria" a scris:

--Use Find/Replace dialog to replace 2010 with 2009

--OR use a formula in cell B1 and copy down
=DATE(2009,MONTH(A1),DAY(A1))

--OR if you are looking for a macro then try

Sub Macro()
Dim cell As Range
For Each cell In Selection
cell.Value = DateAdd("yyyy", -1, cell)
Next
End Sub

--
Jacob


"puiuluipui" wrote:

Hi, in column "A" i have dates. (01.12.2010 ; 02.12.2010 ; 03.12.2010....) I
need to replace only the year.

01.12.2010 01.12.2009
02.12.2010 02.12.2009
03.12.2010 02.12.2009
......

Can a macro replace only the year?
Thanks!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro-replace puiuluipui Excel Discussion (Misc queries) 10 September 20th 09 12:59 PM
Find and replace macro edeaston Excel Discussion (Misc queries) 3 January 12th 09 10:51 AM
Replace Macro Sandy Mann Excel Discussion (Misc queries) 8 December 5th 07 03:05 PM
Macro to Find and Replace R Storey Excel Discussion (Misc queries) 6 December 6th 06 07:04 PM
replace macro? andrewm Excel Worksheet Functions 1 October 19th 05 12:47 PM


All times are GMT +1. The time now is 05:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"