I have a cell with the format "mm/dd/yyyy hh:mm:ss". I want to auto increment the minute, but when I manually auto increment after selecting only that cell, it increments the day. To make it increment the minute, I have to manually copy the cell below, add one minute, select both and THEN increment. Is it possible to, in VBA, specify what part of the cell I want to be incremented when I use the
Selection.AutoFill
function and only have one cell selected? As it is, recording the macro gives me
Selection.AutoFill Destination:=Range("BU2:BU3"), Type:=xlFillDefault
In Excel dates and times are stored differently then in other languages.
From http://www.cpearson.com/excel/datetime.htm
Excel stores dates and times as a number representing the number of
days since 1900-Jan-0, plus a fractional portion of a 24 hour day:
ddddd.tttttt
This is called a serial date, or serial date-time.
If you want to increment by minute then you should add the fraction of a day that is equal to one minute
Minutes in a day = 1440
1 / 1440 = 0.00069444
Set your auto increment function to 0.00069444 and it should work they way you expect.
Related
I have intial date time in this format
'2017-01-01 09:00:00.000'
I want to increment it by preferably by millisecond. Even second will do. I can't find formula for to increment Date time in particular format.
What I found was Time(hours,minutes,seconds) but it does not work.
Assuming your date is in Cell A1. The formula to add 1 second would be =A1+1/86400. To add a millisecond would be =A1+1/86400000. To add 5 milliseconds would be A1+5/86400000
I have an excel worksheet (macro free) set up as follows;
Column W = Shift Start Time
Column X = Shift End Time
Column AE:BB are named 00:00 to 23:00 respectively.
I am trying to count the manpower available by hour e.g. if 1 shift is Start Time 10:00 and Finish 15:00 - this will count 1 for hours 11:00,12:00,13:00 (within AE:BB Table).
The formula currently used is
=COUNTIFS($B$5:$B$76,"<="&AE4,$D$5:$D$76,">="&AE4)
This works when the Shift start time is earlier than finish in one 24 hour period (e.g. 07:00 - 18:00). However, when a night shift finishes the next working day (E.g. 19:00-07:00) any manpower available within that time will not calculate.
Is there a way to incorporate a criteria that considers if Cell W> adjacent cell X into the formula?
Example Source
Current Results
Expected Results
Based on the shift table as follows:
Note that an additional column was added to the shift hours. It was my method for creating an end time on the following day. In Y5 I placed the following formula and copied down:
=IF(X5<W5,X5+1,X5)
It adds 1 to the time when the end time is less than the start time. This essentially adds 1 day to the time. However as long as the cell is formatted to only display time like the other cells, the 1 day is not observed by the user. This modified end time is then used for checking counts.
Place the following formula in AE5 and copy to the right as needed:
=COUNTIFS($W$5:$W$9,"<="&AE4,$Y$5:$Y$9,">"&AE4)+COUNTIFS($W$5:$W$9,"<="&AE4+1,$Y$5:$Y$9,">"&AE4+1)
Check once for regular times and check again for times in the next day and combine the results. Not the > instead of >=. If a shift ends at 1700 then the shift is not available to work from 1700-1800. In your previous example you had them available for the start time block and the end time block. You should count 1 or the other but not both unless you have something that states shift can work 1 hour past their end time or something similar.
I have got a start date and end date in this custom format
dd.mm.yyyy hh:mm in excel cells.
What i need is to fill specific row with dates incremented by half hour from start date to end date using VBA code. And i havent got any idea how to do this.
On web there are some examples with similar problems but with only months or only hours and those are dates format not custom.
You can do this with a simple formula.
Write your start date into cell A1
In A2 write =A1+(1/48)
Copy formula from A2 down
done.
How does this work?
Excel dates are represented as count of days since 1900. That means 1900-01-01 is the first day and represented by 1. All other dates are just the count of days since then. 1 represents one day. So since 1 day has 24 hours 1/48 represents half an hour.
The number format dd.mm.yyyy hh:mm how Excel shows the date is not relevant, because Excel only saves the value (amount of days since 1900) in the cell value.
So if you type the date of today into a cell 2018-10-11 Excel actually saves 43384 in the cell value (today it is 43384ᵗʰ day since 1900-01-01).
One option is to find the interval between start and stop point. Remember that excel dates that are actually dates and not strings are actually integers. The second thing to remember is time is the decimal part which represent fraction of a day. Test if your date (assuming it's in A1) is an actual date or a string with
=ISNUMBER(A1)
If that comes back TRUE you do not need to worry about converting your date. If it comes back FALSE, its actually a string and will need to be converted for excel to work with it.
Divide this interval by 30 minutes, or 30/60/24 to and add 1. This will tell you how many iteration you will need which you can put into a For loop
Start_Number = Range("A1")
End_number = Range(("A2")
Stamp = Start_Number
Interval_number = End_Number - Start_Number
Counter = integer of (Interval_number / (30/60/24))
For x = 1 to counter
write Stamp to cell
Stamp = Stamp + 30/60/24
Next x
Allternatively you could set up a while loop.
Do While datetime < Stop_Point
Write datetime to cell
Datetime=datetime + 30/60/24
Loop
Please note, not actual code but giving idea where OP had no idea where to start.
I have a spreadsheet that lists the date and time of an event in the same cell (mm/dd/yy h:mm). I need to find a way to count how many events took place between a certain time range in a Hourly Basis.
I could sum if the cell contains dates only however the cell contains with date which i am unable to get the values.
Basically, all datas are in cell A, so i need to count how many events happened at 6am, 7am , and so on... as on hourly basis.
Your column A looks like properly formatted date & time value, so its manipulation is easy. If it's not (ie, not date but text) you should first convert it to date value.
=DATE(MID(A2,7,4), MID(A2,4,2), LEFT(A2,2)) + TIME(MID(A2,12,2), MID(A2,15,2), RIGHT(A2,2))
Say this was C2. Now that column C is date & time, set $D$2 to date to query(ex 2017-03-26), E2 to start time(ex 6:00), and F2 to end time(ex 7:00), then you can count events from 6:00 to 7:00 like this:
=COUNTIFS(C:C,">="&($D$2+E2), C:C,"<"&($D$2+F2))
Sample file is here and its screenshot is below.
If the times spanned different dates and you still wanted to see how many events happened in a particular hour of the day, you would need an array-type formula, e.g. if the start time in hours (entered as a normal number) is in C2
=SUMPRODUCT(--(HOUR($A$2:$A$10)=C2))
or if the start hour is entered as a time
=SUMPRODUCT(--(HOUR($A$2:$A$10)=HOUR(C2)))
I am trying to take the values of time passed (formatted HH:MM:SS) and convert it to just minutes.
The issue I am having is that when I try and get the value of the time-value cell, it converts it to some odd value.
Example:
Wrong Value (what Excel gives me now, in worksheet):
34:32:12 = 1.43902777777778
Right Value (what Excel should give me):
34:32:12 = 2072.2
Calcualted:
34*60 + 32 + 12/60
Assuming your source value is in cell A1, here is all you need:
=N(A1*1440)
This method does not require a reformatting of the output cell.
How does it work?
Dates and times are stored in Excel as a combined number... where the integer portion represents the number of days since December 31, 1899 (although the year that Excel calculates from can be changed to 1904 in the Excel Options, but that is immaterial).
The decimal portion of the stored number represents the time component to associate with the date.
Your value of 1.43902777777778 is correct. It states that the ~34.5 hours represents ~1.44 days.
Since you are interested in minutes, we convert that days figure to minutes by multiplying by 1440 as there are 1440 minutes in a day.
The N() function that wraps that calculation ensures that the displayed output is treated as numeric by Excel. Otherwise the output cell would adopt the date-formatting of A1.
Either format the cell as [m] to see 2072, or multiply by 1440 (the number of minutes in a day) and format as 0.0 to see 2072.2