Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Incrementing times and dates

IF USING YOUR HANDS:
may i suggest creating one column with date+time,
if will be easy to increment (write two first lines, select them, then
right clic the small square in the right-bottom, go down, stop on the
final date, in the menu choose to increment as a serial list; not
integer one !)

then put in two adjacent colmuns the formulas:
(example : my column in A, date in B, time in C)
in B1: =DATE(YEAR(A29);MONTH(A29);DAY(A29))
in B2: =TIME(A1)

for each one right-double-clic the right-bottom-square
the formula will propagate down to the end of list

select thoose 2 columns copy / paste-special the values
delete the column A

you have your result

IF USING A MACRO:
then you may add a constant value one to the other
(the step constant must be:
[ {(sec)/60 + min}/60 + hour ]/24 + day
)

and that's all
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Incrementing times and dates

well, excel knows how to work with dates
you do not need all thoose tests (if sec 60 ...)

=================
Sub test()
Dim i&, D As Date, TimeStep As Date, Cell As Range

Set Cell = [A1] ' first cell to write
D = "8-7-2005 00:00" ' start date
TimeStep = "03:05:00" 'date/time increment

For i = 0 To 9 ' 9 means 10 cells
Cell.Offset(i, 0).Value = D
D = D + TimeStep
Next i

End Sub
===================


then , you'll need to understand that excel will change the cell's
format when writing in an empty cell a new data. For example, if you put
a date, the date format will be selected. But if you are entering a
date+time date then the date+time format will be selected.

But if you write a date in an old cell with an other format, then the
date will not be written as wished. You may change the format of cells
before writing into them...


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Incrementing times and dates

doh - just thought - of course the dates are manipulated first and then
added to the string.
BTW I managed to finish my project using my old methods but this is useful
info.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Incrementing times and dates

well take a better look: these are not strings

they are converted from strings to dates
just because of the Dim declaration

D is supposed to be a date, so D = "..."
makes VBA try to convert the "..." to the date type.

But you may use D = CDate("...") if you want to much more understand the
key of my code. (this CDAte is auto-added by VBA by default)
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Incrementing times and dates

well take a better look: these are not strings

they are converted from strings to dates
just because of the Dim declaration

D is supposed to be a date, so D = "..."
makes VBA try to convert the "..." to the date type.

But you may use D = CDate("...") if you want to much more understand the
key of my code. (this CDAte is auto-added by VBA by default)


Many thanks,

I have improved my code by using your method - it saved me a lot of time and
stress.

Cheers

JS


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
Calculate times between dates and times in Excel Helio Excel Discussion (Misc queries) 1 March 25th 10 04:29 AM
Incrementing dates in the format MMM-YY kmewing Excel Discussion (Misc queries) 3 October 19th 07 06:03 PM
Repeating/incrementing dates 35039 times Daiv Excel Discussion (Misc queries) 5 January 4th 07 09:54 PM
Question re incrementing Dates by one month SA3214 Excel Programming 2 May 7th 05 12:27 AM
Incrementing dates by one hour returns bad result jennifer Excel Programming 0 November 19th 03 06:45 PM


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