Macro Help with Changing String Characters

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

willydigger

Thread Starter
Joined
Jul 24, 2003
Messages
112
I have a column of dates that end in 2004. I need to change each date to 2005. They don't go in sequential order so I can't drag. How do I change an individual character in a string.

Set rngCurrent = Range("A2:A8742")
For Each rngCell In rngCurrent
If Right(rngCell, 1) = 4 Then
????
End If
Next rngCell
 
Joined
Aug 5, 2005
Messages
3,086
The missing line is

rngCell = Left(rngCell.Value, Len(rngCell.Value) - 1) & "5"

BUT.

This is going to change the data type of the cells from date to string.

Because dates are actually referential instances in time, they're stored as floating-point numbers. So, I guess something you could try, though I have no idea if it would work, would be to add 365.24 to the cell's value:

rngCell = rngCell.Value + 365.24

I don't know much about Excel or its object model. Others will bump a better solution, I'm sure.

chris.
 
Joined
Jul 1, 2005
Messages
8,546
Found on Google:

Sub Macro1()
Set rngCurrent = Range("A2:A8742")
For Each rngCell In rngCurrent
With rngCell
If IsDate(.Value) Then
.Value = DateSerial(Year(.Value) + 1, _
Month(.Value), Day(.Value))
End If
End With
Next rngCell
End Sub


However, not sure it's worth it. You could just use Find & Replace (CTRL+H -- replace 2004 with 2005) ... as long as you remember to check for 29 Feb 2005 after. ;)
 
Joined
Aug 5, 2005
Messages
3,086
^^ The better solution I anticipated.

If you're happy with the resolution, you may mark this thread "Solved" using the Thread Tools at the top of the page.

chris.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top