Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Date + one year

I have a long column of birthdays formulated 8/12/05
I want to change all the dates to next year i.e. 8/12/06

oldjay


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Date + one year


considering your date 8/12/05 is written in a1
in b1 type this formula --- =a1+365
you will get 8/12/06
copy it down until where you want
Syed


--
saziz
------------------------------------------------------------------------
saziz's Profile: http://www.excelforum.com/member.php...fo&userid=6350
View this thread: http://www.excelforum.com/showthread...hreadid=493623

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Date + one year

In an empty column adjacent to your dates, use the following
formula:

=DATE(YEAR(A1)+1,MONTH(A1),DAY(A1))

Copy this formula down as far as you need to go. Select the cells
with this formula, right-click on the right edge, and drag over
the original data. When you release the right-button, choose
"Copy Here As Values Only"


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Oldjay" wrote in message
...
I have a long column of birthdays formulated 8/12/05
I want to change all the dates to next year i.e. 8/12/06

oldjay




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Date + one year

YourDate+365 fails in a leap year.

You might try the Edate() function.

=Edate(ReferenceToYourDate,12)

If Edate() doesn't work for you, read the reference in Help.

If you want to write a macro, DateSerial is the key:

Function AddAYear(Yourdate As Date) As Date
AddAYear = DateSerial(Year(Yourdate) + 1, Month(Yourdate), Day(Yourdate))
End Function

Steve


"saziz" wrote in
message ...

considering your date 8/12/05 is written in a1
in b1 type this formula --- =a1+365
you will get 8/12/06
copy it down until where you want
Syed


--
saziz
------------------------------------------------------------------------
saziz's Profile:
http://www.excelforum.com/member.php...fo&userid=6350
View this thread: http://www.excelforum.com/showthread...hreadid=493623



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Date + one year

This will do it in VBA:

Function AddOneYear(daDate As Date) As Date

AddOneYear = DateSerial(Year(daDate) + 1, Month(daDate), Day(daDate))

End Function


Sub test()

Dim i As Long

For i = 1 To 100
Cells(i, 2) = Format(AddOneYear(Cells(i, 1)), "dd/mm/yy")
Next

End Sub


RBS


"Oldjay" wrote in message
...
I have a long column of birthdays formulated 8/12/05
I want to change all the dates to next year i.e. 8/12/06

oldjay





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Date + one year


You are right Steve. It will fail in a Leap year
Thank you for pointing that out.
Sye

--
sazi
-----------------------------------------------------------------------
saziz's Profile: http://www.excelforum.com/member.php...nfo&userid=635
View this thread: http://www.excelforum.com/showthread.php?threadid=49362

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 337
Default Date + one year

A little more detail. The birthdays are in the 4th column of a 8 column list.
I would like the macro to change them in place
oldjay

"RB Smissaert" wrote:

This will do it in VBA:

Function AddOneYear(daDate As Date) As Date

AddOneYear = DateSerial(Year(daDate) + 1, Month(daDate), Day(daDate))

End Function


Sub test()

Dim i As Long

For i = 1 To 100
Cells(i, 2) = Format(AddOneYear(Cells(i, 1)), "dd/mm/yy")
Next

End Sub


RBS


"Oldjay" wrote in message
...
I have a long column of birthdays formulated 8/12/05
I want to change all the dates to next year i.e. 8/12/06

oldjay




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Date + one year

Hi Oldjay,

Try:

'=============
Sub AddOneYear()
Dim rng As Range
Dim rcell As Range
Dim WB As Workbook
Dim SH As Worksheet
Dim LRow As Long
Dim CalcMode As Long
Const col As String = "D" '<<===== CHANGE

Set WB = ThisWorkbook '<<===== CHANGE
Set SH = WB.Sheets("Birthday") '<<===== CHANGE

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

LRow = SH.Cells(Rows.Count, col).End(xlUp)

Set rng = SH.Range(col & 2).Resize(LRow - 1)

For Each rcell In rng.Cells
With rcell
If IsDate(.Value) Then
.Value = DateSerial(Year(.Value) + 1, _
Month(.Value), Day(.Value))
End If
End With
Next rcell

With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

End Sub
'<<=============

Change the sheet and workbook names to suit.

As written, the macro will add a year to all dates in column D and allows
for headers in row 1.

--
---
Regards,
Norman



"Oldjay" wrote in message
...
A little more detail. The birthdays are in the 4th column of a 8 column
list.
I would like the macro to change them in place
oldjay

"RB Smissaert" wrote:

This will do it in VBA:

Function AddOneYear(daDate As Date) As Date

AddOneYear = DateSerial(Year(daDate) + 1, Month(daDate), Day(daDate))

End Function


Sub test()

Dim i As Long

For i = 1 To 100
Cells(i, 2) = Format(AddOneYear(Cells(i, 1)), "dd/mm/yy")
Next

End Sub


RBS


"Oldjay" wrote in message
...
I have a long column of birthdays formulated 8/12/05
I want to change all the dates to next year i.e. 8/12/06

oldjay






  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 337
Default Date + one year

When I put in the name of the workbook I get an error saying "Expected: End
of statement" with Manor highlighted

Set WB = RIDGE MANOR COMMUNITY UNITED METHODIST CHURCH MEMBERSHIP LISTV1.XLS
'<<===== CHANGE

oldjay

"Norman Jones" wrote:

Hi Oldjay,

Try:

'=============
Sub AddOneYear()
Dim rng As Range
Dim rcell As Range
Dim WB As Workbook
Dim SH As Worksheet
Dim LRow As Long
Dim CalcMode As Long
Const col As String = "D" '<<===== CHANGE

Set WB = ThisWorkbook '<<===== CHANGE
Set SH = WB.Sheets("Birthday") '<<===== CHANGE

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

LRow = SH.Cells(Rows.Count, col).End(xlUp)

Set rng = SH.Range(col & 2).Resize(LRow - 1)

For Each rcell In rng.Cells
With rcell
If IsDate(.Value) Then
.Value = DateSerial(Year(.Value) + 1, _
Month(.Value), Day(.Value))
End If
End With
Next rcell

With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

End Sub
'<<=============

Change the sheet and workbook names to suit.

As written, the macro will add a year to all dates in column D and allows
for headers in row 1.

--
---
Regards,
Norman



"Oldjay" wrote in message
...
A little more detail. The birthdays are in the 4th column of a 8 column
list.
I would like the macro to change them in place
oldjay

"RB Smissaert" wrote:

This will do it in VBA:

Function AddOneYear(daDate As Date) As Date

AddOneYear = DateSerial(Year(daDate) + 1, Month(daDate), Day(daDate))

End Function


Sub test()

Dim i As Long

For i = 1 To 100
Cells(i, 2) = Format(AddOneYear(Cells(i, 1)), "dd/mm/yy")
Next

End Sub


RBS


"Oldjay" wrote in message
...
I have a long column of birthdays formulated 8/12/05
I want to change all the dates to next year i.e. 8/12/06

oldjay







  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Date + one year


Hi Oldjay,

If the code is to be housed in the RIDGE MANOR COMMUNITY UNITED METHODIST
CHURCH MEMBERSHIP LISTV1.XLS workbook, you can leave the original:

Set WB = ThisWorkbook


Otherwise, try:

Set WB = Workbooks("RIDGE MANOR " _
& "COMMUNITY UNITED METHODIST " _
& "CHURCH MEMBERSHIP LISTV1.XLS")


---
Regards,
Norman


"Oldjay" wrote in message
...
When I put in the name of the workbook I get an error saying "Expected:
End
of statement" with Manor highlighted

Set WB = RIDGE MANOR COMMUNITY UNITED METHODIST CHURCH MEMBERSHIP
LISTV1.XLS
'<<===== CHANGE

oldjay

"Norman Jones" wrote:

Hi Oldjay,

Try:

'=============
Sub AddOneYear()
Dim rng As Range
Dim rcell As Range
Dim WB As Workbook
Dim SH As Worksheet
Dim LRow As Long
Dim CalcMode As Long
Const col As String = "D" '<<===== CHANGE

Set WB = ThisWorkbook '<<===== CHANGE
Set SH = WB.Sheets("Birthday") '<<===== CHANGE

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

LRow = SH.Cells(Rows.Count, col).End(xlUp)

Set rng = SH.Range(col & 2).Resize(LRow - 1)

For Each rcell In rng.Cells
With rcell
If IsDate(.Value) Then
.Value = DateSerial(Year(.Value) + 1, _
Month(.Value), Day(.Value))
End If
End With
Next rcell

With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

End Sub
'<<=============

Change the sheet and workbook names to suit.

As written, the macro will add a year to all dates in column D and allows
for headers in row 1.

--
---
Regards,
Norman





  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 337
Default Date + one year

Norman,

The code works great. Thanks

I have another column with Anniversaries that I also want to convert. I
tried to just change the Const col As String = "J" to Const col As String =
"K" at the botton of the sub and re-copy the code below This doesn't work. It
gives the error"Duplicate declaration in current scope"

oldjay

"Norman Jones" wrote:


Hi Oldjay,

If the code is to be housed in the RIDGE MANOR COMMUNITY UNITED METHODIST
CHURCH MEMBERSHIP LISTV1.XLS workbook, you can leave the original:

Set WB = ThisWorkbook


Otherwise, try:

Set WB = Workbooks("RIDGE MANOR " _
& "COMMUNITY UNITED METHODIST " _
& "CHURCH MEMBERSHIP LISTV1.XLS")


---
Regards,
Norman


"Oldjay" wrote in message
...
When I put in the name of the workbook I get an error saying "Expected:
End
of statement" with Manor highlighted

Set WB = RIDGE MANOR COMMUNITY UNITED METHODIST CHURCH MEMBERSHIP
LISTV1.XLS
'<<===== CHANGE

oldjay

"Norman Jones" wrote:

Hi Oldjay,

Try:

'=============
Sub AddOneYear()
Dim rng As Range
Dim rcell As Range
Dim WB As Workbook
Dim SH As Worksheet
Dim LRow As Long
Dim CalcMode As Long
Const col As String = "D" '<<===== CHANGE

Set WB = ThisWorkbook '<<===== CHANGE
Set SH = WB.Sheets("Birthday") '<<===== CHANGE

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

LRow = SH.Cells(Rows.Count, col).End(xlUp)

Set rng = SH.Range(col & 2).Resize(LRow - 1)

For Each rcell In rng.Cells
With rcell
If IsDate(.Value) Then
.Value = DateSerial(Year(.Value) + 1, _
Month(.Value), Day(.Value))
End If
End With
Next rcell

With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

End Sub
'<<=============

Change the sheet and workbook names to suit.

As written, the macro will add a year to all dates in column D and allows
for headers in row 1.

--
---
Regards,
Norman




  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Date + one year

Hi Oldjay,

Try replacing your code with:

'=============
Sub ChangeYear()
Call AddOneYear("J")
Call AddOneYear("K")
End Sub
'<<=============

'=============
Sub AddOneYear(col As String)
Dim rng As Range
Dim rcell As Range
Dim WB As Workbook
Dim SH As Worksheet
Dim LRow As Long
Dim CalcMode As Long

Set WB = ThisWorkbook '<<===== CHANGE
Set SH = WB.Sheets("Birthday") '<<===== CHANGE

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

LRow = SH.Cells(Rows.Count, col).End(xlUp)

Set rng = SH.Range(col & 2).Resize(LRow - 1)

For Each rcell In rng.Cells
With rcell
If IsDate(.Value) Then
.Value = DateSerial(Year(.Value) + 1, _
Month(.Value), Day(.Value))
End If
End With
Next rcell

With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

End Sub
'<<=============

Now instead of running the AddOneYear procedure directly, run the ChangeYear
procedure.

In the ChangeYear sub, change J and K to the date columns of interest.


---
Regards,
Norman



"Oldjay" wrote in message
...
Norman,

The code works great. Thanks

I have another column with Anniversaries that I also want to convert. I
tried to just change the Const col As String = "J" to Const col As String
=
"K" at the botton of the sub and re-copy the code below This doesn't work.
It
gives the error"Duplicate declaration in current scope"

oldjay

"Norman Jones" wrote:


Hi Oldjay,

If the code is to be housed in the RIDGE MANOR COMMUNITY UNITED METHODIST
CHURCH MEMBERSHIP LISTV1.XLS workbook, you can leave the original:

Set WB = ThisWorkbook


Otherwise, try:

Set WB = Workbooks("RIDGE MANOR " _
& "COMMUNITY UNITED METHODIST " _
& "CHURCH MEMBERSHIP LISTV1.XLS")


---
Regards,
Norman



  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 337
Default Date + one year

Everything works peachy. Thanks again
It amazes me that you guys can help so many people in such a short response
time

oldjay

"Norman Jones" wrote:

Hi Oldjay,

Try replacing your code with:

'=============
Sub ChangeYear()
Call AddOneYear("J")
Call AddOneYear("K")
End Sub
'<<=============

'=============
Sub AddOneYear(col As String)
Dim rng As Range
Dim rcell As Range
Dim WB As Workbook
Dim SH As Worksheet
Dim LRow As Long
Dim CalcMode As Long

Set WB = ThisWorkbook '<<===== CHANGE
Set SH = WB.Sheets("Birthday") '<<===== CHANGE

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

LRow = SH.Cells(Rows.Count, col).End(xlUp)

Set rng = SH.Range(col & 2).Resize(LRow - 1)

For Each rcell In rng.Cells
With rcell
If IsDate(.Value) Then
.Value = DateSerial(Year(.Value) + 1, _
Month(.Value), Day(.Value))
End If
End With
Next rcell

With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

End Sub
'<<=============

Now instead of running the AddOneYear procedure directly, run the ChangeYear
procedure.

In the ChangeYear sub, change J and K to the date columns of interest.


---
Regards,
Norman



"Oldjay" wrote in message
...
Norman,

The code works great. Thanks

I have another column with Anniversaries that I also want to convert. I
tried to just change the Const col As String = "J" to Const col As String
=
"K" at the botton of the sub and re-copy the code below This doesn't work.
It
gives the error"Duplicate declaration in current scope"

oldjay

"Norman Jones" wrote:


Hi Oldjay,

If the code is to be housed in the RIDGE MANOR COMMUNITY UNITED METHODIST
CHURCH MEMBERSHIP LISTV1.XLS workbook, you can leave the original:

Set WB = ThisWorkbook

Otherwise, try:

Set WB = Workbooks("RIDGE MANOR " _
& "COMMUNITY UNITED METHODIST " _
& "CHURCH MEMBERSHIP LISTV1.XLS")


---
Regards,
Norman




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
Date(Year,Month,Day) not returnign correct date jlclyde Excel Discussion (Misc queries) 8 October 16th 09 02:42 PM
Determine year over year date for comparison zeroscou Excel Worksheet Functions 3 March 6th 09 10:01 PM
Sorting a date by month, date and then year. drosh Excel Discussion (Misc queries) 3 May 30th 08 01:57 AM
Year-to-date year to date formula Philm Excel Worksheet Functions 1 October 7th 05 02:50 AM
Date formula: return Quarter and Fiscal Year of a date Rob Excel Discussion (Misc queries) 7 May 11th 05 08:48 PM


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

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"