Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA time calculation
I have created a command button. When I click it, I want it to get the
current time, add 16 hours to the current it, and enter that time in the selected cell. I have spent way too much time trying to figure this out and I am ready to pull my hair out. By the way, I am using Excel 2000. Any help would be greatly appreciated! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA time calculation
Private Sub CommandButton1_Click()
dt = Time ActiveCell.Value = Format(dt + TimeValue("16:00:00"), "hh:mm:ss am/ pm") End Sub On Oct 22, 11:32*am, Nancy T. wrote: I have created a command button. When I click it, I want it to get the current time, add 16 hours to the current it, and enter that time in the selected cell. I have spent way too much time trying to figure this out and I am ready to pull my hair out. By the way, I am using Excel 2000. Any help would be greatly appreciated! |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA time calculation
This line of code should do what you want...
ActiveCell.Value = Time + TimeSerial(16, 0, 0) You can, of course, format the cell to display this time in whatever format you choose. Or you can set the NumberFormat property via code. For example (to suppress the seconds using a 24-hour clock)... ActiveCell.NumberFormat = "hh:mm" -- Rick (MVP - Excel) "Nancy T." wrote in message ... I have created a command button. When I click it, I want it to get the current time, add 16 hours to the current it, and enter that time in the selected cell. I have spent way too much time trying to figure this out and I am ready to pull my hair out. By the way, I am using Excel 2000. Any help would be greatly appreciated! |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA time calculation
Activecell.Value = DateAdd("h", 16, Now()) "Nancy T." wrote: I have created a command button. When I click it, I want it to get the current time, add 16 hours to the current it, and enter that time in the selected cell. I have spent way too much time trying to figure this out and I am ready to pull my hair out. By the way, I am using Excel 2000. Any help would be greatly appreciated! |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA time calculation
By the way, if you are only adding hours (even if decimal hours such as
14.25), then you can simplify this to the following... ActiveCell = Time + 16/24 where you would replace the 16 by your decimal hours. -- Rick (MVP - Excel) "Rick Rothstein" wrote in message ... This line of code should do what you want... ActiveCell.Value = Time + TimeSerial(16, 0, 0) You can, of course, format the cell to display this time in whatever format you choose. Or you can set the NumberFormat property via code. For example (to suppress the seconds using a 24-hour clock)... ActiveCell.NumberFormat = "hh:mm" -- Rick (MVP - Excel) "Nancy T." wrote in message ... I have created a command button. When I click it, I want it to get the current time, add 16 hours to the current it, and enter that time in the selected cell. I have spent way too much time trying to figure this out and I am ready to pull my hair out. By the way, I am using Excel 2000. Any help would be greatly appreciated! |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA time calculation
Thanks everyone! I knew I was making it more difficult than it needed to be.
(My only excuse is that it was about 1:00 AM by the time I threw in the towel and came here!) These are all perfect. Gratefully, --Nancy |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Stop time - start time calculation | Excel Worksheet Functions | |||
Time calculation (Subraction of Idle Time) | Excel Discussion (Misc queries) | |||
Time calculation | Excel Worksheet Functions | |||
Ignoring Time in a Date Time Calculation | Excel Worksheet Functions | |||
time calculation with military time | Excel Worksheet Functions |