Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Calculate times between dates and times in Excel | Excel Discussion (Misc queries) | |||
Incrementing dates in the format MMM-YY | Excel Discussion (Misc queries) | |||
Repeating/incrementing dates 35039 times | Excel Discussion (Misc queries) | |||
Question re incrementing Dates by one month | Excel Programming | |||
Incrementing dates by one hour returns bad result | Excel Programming |