Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Changing the value of a year in a given format

I'm trying to write a sub that will take a date from a given cell - say
1/01/2006, and then change that to read 1/01/2004. I would physically go in
to do it to each cell, however, there' s over 10,000 cells, and I thought a
program would be easier. Any assistance in this matter would be greatly
appreciated. Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Changing the value of a year in a given format

Untested

For Each cell In Selection
With cell
If IsDate(.VAlue) Then
If Year(.Value) = 2006 Then
.Value =
DateSerial(Year(.Value)-2,Month(.value),Day(.Value))
End If
End If
End With
Next cell

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"cdbiggs" wrote in message
...
I'm trying to write a sub that will take a date from a given cell - say
1/01/2006, and then change that to read 1/01/2004. I would physically go

in
to do it to each cell, however, there' s over 10,000 cells, and I thought

a
program would be easier. Any assistance in this matter would be greatly
appreciated. Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Changing the value of a year in a given format

I typed it in verbatim, and I get an error box that only says "400"...???

Not sure what that means.


"Bob Phillips" wrote:

Untested

For Each cell In Selection
With cell
If IsDate(.VAlue) Then
If Year(.Value) = 2006 Then
.Value =
DateSerial(Year(.Value)-2,Month(.value),Day(.Value))
End If
End If
End With
Next cell

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"cdbiggs" wrote in message
...
I'm trying to write a sub that will take a date from a given cell - say
1/01/2006, and then change that to read 1/01/2004. I would physically go

in
to do it to each cell, however, there' s over 10,000 cells, and I thought

a
program would be easier. Any assistance in this matter would be greatly
appreciated. Thanks.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Changing the value of a year in a given format

Try this

For Each cell In Selection
With cell
If IsDate(.Value) Then
If Year(.Value) = 2006 Then
.Value = DateSerial(Year(.Value) - 2, _
Month(.Value), Day(.Value))
End If
End If
End With
Next cell


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"cdbiggs" wrote in message
...
I typed it in verbatim, and I get an error box that only says "400"...???

Not sure what that means.


"Bob Phillips" wrote:

Untested

For Each cell In Selection
With cell
If IsDate(.VAlue) Then
If Year(.Value) = 2006 Then
.Value =
DateSerial(Year(.Value)-2,Month(.value),Day(.Value))
End If
End If
End With
Next cell

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"cdbiggs" wrote in message
...
I'm trying to write a sub that will take a date from a given cell -

say
1/01/2006, and then change that to read 1/01/2004. I would physically

go
in
to do it to each cell, however, there' s over 10,000 cells, and I

thought
a
program would be easier. Any assistance in this matter would be

greatly
appreciated. Thanks.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Changing the value of a year in a given format

Bob,

No...this didn't work. For some reason, it's not even looping through. It
wouldn't even change the first one on the worksheet, which is in cell A1.
All the dates are in the "A" column.

"Bob Phillips" wrote:

Try this

For Each cell In Selection
With cell
If IsDate(.Value) Then
If Year(.Value) = 2006 Then
.Value = DateSerial(Year(.Value) - 2, _
Month(.Value), Day(.Value))
End If
End If
End With
Next cell


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"cdbiggs" wrote in message
...
I typed it in verbatim, and I get an error box that only says "400"...???

Not sure what that means.


"Bob Phillips" wrote:

Untested

For Each cell In Selection
With cell
If IsDate(.VAlue) Then
If Year(.Value) = 2006 Then
.Value =
DateSerial(Year(.Value)-2,Month(.value),Day(.Value))
End If
End If
End With
Next cell

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"cdbiggs" wrote in message
...
I'm trying to write a sub that will take a date from a given cell -

say
1/01/2006, and then change that to read 1/01/2004. I would physically

go
in
to do it to each cell, however, there' s over 10,000 cells, and I

thought
a
program would be easier. Any assistance in this matter would be

greatly
appreciated. 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
Changing year in a data cell Jim Excel Discussion (Misc queries) 3 March 24th 09 03:34 PM
convert day of year to numeric value format year+day in 4 digits Kaaren Excel Worksheet Functions 3 February 7th 09 08:37 PM
Automatically changing Year archergirl2000 Excel Discussion (Misc queries) 3 May 15th 06 08:59 PM
changing the year of a date zapszipszops Excel Worksheet Functions 2 April 14th 06 04:57 AM
Changing the year only in a date cs_vision Excel Programming 1 June 8th 05 05:19 PM


All times are GMT +1. The time now is 08:29 AM.

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

About Us

"It's about Microsoft Excel"