Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default How can I make For-Next loop with date?

Hi,

I am trying to make a loop, starting date 7/1/2001 and ending date
8/12/2005, which would write the results starting with Cells(1,1). By the
way, I would like to increment it with a day was wondering how I can do this?

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How can I make For-Next loop with date?


Hello GreenInIowa,

This example will list the dates in column A of the worksheet. I wasn't
sure about the incrementing by day part. Did you mean by day of the week
or day of the month?


Sub LoopDate()

Dim I
Dim R As Long

For I = CVDate("07/01/2001") To CVDate("8/12/2005")
R = R + 1
Cells(R, 1).Value = I
Next I

End Sub


This should help get you going.

Sincerely,


--
Leith Ross


------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=476116

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default How can I make For-Next loop with date?

Hi Leith,

This is works great. But, I tried your loop without CVDate( ) for example
#07/01/2001#. It gave me similar results and was wondering why we use CVDate(
) for? Also, if we want to increment your code by "month" rather than "day",
how do we do it, for example, 4/4/2000, 5/4/2000, ....12/4/2004?

Thanks

"Leith Ross" wrote:


Hello GreenInIowa,

This example will list the dates in column A of the worksheet. I wasn't
sure about the incrementing by day part. Did you mean by day of the week
or day of the month?


Sub LoopDate()

Dim I
Dim R As Long

For I = CVDate("07/01/2001") To CVDate("8/12/2005")
R = R + 1
Cells(R, 1).Value = I
Next I

End Sub


This should help get you going.

Sincerely,


--
Leith Ross


------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=476116


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
How can I make For-Next loop with date? JS2004R6 Excel Programming 0 October 14th 05 05:20 AM
I want to make one loop David Excel Programming 2 October 12th 05 01:35 AM
How to Make a Loop count by 1% not 1 MichaelC Excel Programming 8 June 12th 05 02:04 AM
Date selection loop Roger[_8_] Excel Programming 12 September 26th 04 12:53 AM
Help with macro to make it loop through coloums R Krishna Excel Programming 0 July 29th 03 04:54 PM


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

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

About Us

"It's about Microsoft Excel"