LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Mig Mig is offline
external usenet poster
 
Posts: 4
Default How do I write a VBA for 3 consecutive dates?

I am a VBA newbie and I am reformatting some older data by entering two
consecutive dates on separate rows. For example A1 (1/1/2006) has a date and
I need A2 and A3 to equal the next two days (i.e., 1/2/2006 and 1/3/2006).

I also dont know how to define cells as dates and how to assign a value
defined by a variable to a cell. The code below makes logical sense but the
syntax is wrong and I dont know how to fix it. Thank you for your help.

Sub Dates_OfCapture()

Dim Startdate As Date
Dim N1 As Integer
Dim N2 As Integer
Dim x As Integer
x = 10 'starting row
y = 1 'add one day

For N1 = 1 To 100
For N2 = 1 To 2 'two turns of For Loop for every Startdate
z = x + 1
Startdate = Cells(x, 2).Date 'defining the Startdate
Cells(z, 2).Date = DateAdd("dd", y, Startdate) 'adding a day to the
row below the starting date
x = x + 1 'add one to the the row number
y = y + 1 'add one to the number of days beind added to Startdate
Next N2
z = 1 'reset z (number of days added) back to 1
Next N1

End Sub
 
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
consecutive dates mdorrill Excel Discussion (Misc queries) 2 March 14th 08 12:25 PM
consecutive bi-monthly dates dmr Excel Worksheet Functions 4 September 20th 07 09:47 PM
how do I sort a column of random dates into Consecutive dates Rob Gibson Excel Worksheet Functions 2 June 12th 07 05:10 AM
Printing consecutive dates Bradford88 Excel Discussion (Misc queries) 1 January 22nd 07 07:33 PM
Assigning consecutive dates Brooke Excel Worksheet Functions 14 August 14th 06 10:45 PM


All times are GMT +1. The time now is 10:36 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"