PC Review


Reply
Thread Tools Rate Thread

Add days to date

 
 
tomjoe
Guest
Posts: n/a
 
      21st Feb 2010
I want the code to pick dates from column Q (see line 4) add 7 days and put
the new dates into column k.

Any suggestions?

Sub copy_Dates()
Sheets(2).Range("e4:e65536").Value = Sheets(1).Range("d4:d65536")
Sheets(1).Range("n4:Q65536").Value = Sheets(2).Range("f4:i65536").Value
Sheets(1).Range("k4:K65536").Value = Range("q4:q65536").Value
Sheets(1).Select
Range("k65536").End(xlUp).Activate
If ActiveCell.Value <= Now - 30 Then
msgbox "NICE!!"
Else: Exit Sub
End If
End Sub

 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      21st Feb 2010
Hi,

Use the DateAdd method. This adds 7 days to a date in Col Q and puts it in
Col K

Sub Copy_Dates()
Set sht = Sheets(1)
Dim LastRow As Long
Dim c As Range
LastRow = sht.Cells(Cells.Rows.Count, "Q").End(xlUp).Row
Set MyRange = sht.Range("Q4:Q" & LastRow)
For Each c In MyRange
If IsDate(c) Then
c.Offset(, -6).Value = DateAdd("d", 7, c.Value)
End If
Next
End Sub

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"tomjoe" wrote:

> I want the code to pick dates from column Q (see line 4) add 7 days and put
> the new dates into column k.
>
> Any suggestions?
>
> Sub copy_Dates()
> Sheets(2).Range("e4:e65536").Value = Sheets(1).Range("d4:d65536")
> Sheets(1).Range("n4:Q65536").Value = Sheets(2).Range("f4:i65536").Value
> Sheets(1).Range("k4:K65536").Value = Range("q4:q65536").Value
> Sheets(1).Select
> Range("k65536").End(xlUp).Activate
> If ActiveCell.Value <= Now - 30 Then
> msgbox "NICE!!"
> Else: Exit Sub
> End If
> End Sub
>

 
Reply With Quote
 
tomjoe
Guest
Posts: n/a
 
      21st Feb 2010
Hi Mike
Worked like a charm.
Awsome simple and terrible smart.
Thank you so much.


Mike H skrev:

> Hi,
>
> Use the DateAdd method. This adds 7 days to a date in Col Q and puts it in
> Col K
>
> Sub Copy_Dates()
> Set sht = Sheets(1)
> Dim LastRow As Long
> Dim c As Range
> LastRow = sht.Cells(Cells.Rows.Count, "Q").End(xlUp).Row
> Set MyRange = sht.Range("Q4:Q" & LastRow)
> For Each c In MyRange
> If IsDate(c) Then
> c.Offset(, -6).Value = DateAdd("d", 7, c.Value)
> End If
> Next
> End Sub
>
> --
> Mike
>
> When competing hypotheses are otherwise equal, adopt the hypothesis that
> introduces the fewest assumptions while still sufficiently answering the
> question.
>
>
> "tomjoe" wrote:
>
> > I want the code to pick dates from column Q (see line 4) add 7 days and put
> > the new dates into column k.
> >
> > Any suggestions?
> >
> > Sub copy_Dates()
> > Sheets(2).Range("e4:e65536").Value = Sheets(1).Range("d4:d65536")
> > Sheets(1).Range("n4:Q65536").Value = Sheets(2).Range("f4:i65536").Value
> > Sheets(1).Range("k4:K65536").Value = Range("q4:q65536").Value
> > Sheets(1).Select
> > Range("k65536").End(xlUp).Activate
> > If ActiveCell.Value <= Now - 30 Then
> > msgbox "NICE!!"
> > Else: Exit Sub
> > End If
> > End Sub
> >

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      21st Feb 2010
Glad i could help and thanks for the feedback
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"tomjoe" wrote:

> Hi Mike
> Worked like a charm.
> Awsome simple and terrible smart.
> Thank you so much.
>
>
> Mike H skrev:
>
> > Hi,
> >
> > Use the DateAdd method. This adds 7 days to a date in Col Q and puts it in
> > Col K
> >
> > Sub Copy_Dates()
> > Set sht = Sheets(1)
> > Dim LastRow As Long
> > Dim c As Range
> > LastRow = sht.Cells(Cells.Rows.Count, "Q").End(xlUp).Row
> > Set MyRange = sht.Range("Q4:Q" & LastRow)
> > For Each c In MyRange
> > If IsDate(c) Then
> > c.Offset(, -6).Value = DateAdd("d", 7, c.Value)
> > End If
> > Next
> > End Sub
> >
> > --
> > Mike
> >
> > When competing hypotheses are otherwise equal, adopt the hypothesis that
> > introduces the fewest assumptions while still sufficiently answering the
> > question.
> >
> >
> > "tomjoe" wrote:
> >
> > > I want the code to pick dates from column Q (see line 4) add 7 days and put
> > > the new dates into column k.
> > >
> > > Any suggestions?
> > >
> > > Sub copy_Dates()
> > > Sheets(2).Range("e4:e65536").Value = Sheets(1).Range("d4:d65536")
> > > Sheets(1).Range("n4:Q65536").Value = Sheets(2).Range("f4:i65536").Value
> > > Sheets(1).Range("k4:K65536").Value = Range("q4:q65536").Value
> > > Sheets(1).Select
> > > Range("k65536").End(xlUp).Activate
> > > If ActiveCell.Value <= Now - 30 Then
> > > msgbox "NICE!!"
> > > Else: Exit Sub
> > > End If
> > > End Sub
> > >

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      21st Feb 2010
Or just add 7 (since you're adding days):

If IsDate(c) Then
with c.Offset(, -6)
.Value = .value + 7
end with
End If

Mike H wrote:
>
> Hi,
>
> Use the DateAdd method. This adds 7 days to a date in Col Q and puts it in
> Col K
>
> Sub Copy_Dates()
> Set sht = Sheets(1)
> Dim LastRow As Long
> Dim c As Range
> LastRow = sht.Cells(Cells.Rows.Count, "Q").End(xlUp).Row
> Set MyRange = sht.Range("Q4:Q" & LastRow)
> For Each c In MyRange
> If IsDate(c) Then
> c.Offset(, -6).Value = DateAdd("d", 7, c.Value)
> End If
> Next
> End Sub
>
> --
> Mike
>
> When competing hypotheses are otherwise equal, adopt the hypothesis that
> introduces the fewest assumptions while still sufficiently answering the
> question.
>
> "tomjoe" wrote:
>
> > I want the code to pick dates from column Q (see line 4) add 7 days and put
> > the new dates into column k.
> >
> > Any suggestions?
> >
> > Sub copy_Dates()
> > Sheets(2).Range("e4:e65536").Value = Sheets(1).Range("d4:d65536")
> > Sheets(1).Range("n4:Q65536").Value = Sheets(2).Range("f4:i65536").Value
> > Sheets(1).Range("k4:K65536").Value = Range("q4:q65536").Value
> > Sheets(1).Select
> > Range("k65536").End(xlUp).Activate
> > If ActiveCell.Value <= Now - 30 Then
> > msgbox "NICE!!"
> > Else: Exit Sub
> > End If
> > End Sub
> >


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to pull <=14 Days, <=30 Days, >30 Days from a date column Ken Microsoft Excel Misc 3 23rd Oct 2009 12:53 AM
Conditional Formatting Dates calculating 10 days and 30 days from a certain date Sioux Microsoft Excel Worksheet Functions 2 11th Oct 2007 02:04 PM
Todays date minus 6 days before (Shows all records in 6 days) =?Utf-8?B?UmFjaA==?= Microsoft Access Queries 2 14th Sep 2007 12:46 PM
Determine dates by number of days, "what date is 180 days from now =?Utf-8?B?VFJMYW1i?= Microsoft Outlook Calendar 2 19th Apr 2007 03:30 PM
Business Days for based on a date of 7 days ago or longer =?Utf-8?B?QmFyYmFyYQ==?= Microsoft Access Queries 1 27th Oct 2003 09:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:34 PM.