Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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
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
Stop time - start time calculation squack21 Excel Worksheet Functions 5 December 10th 07 03:20 PM
Time calculation (Subraction of Idle Time) Ajay Excel Discussion (Misc queries) 6 March 4th 07 11:54 AM
Time calculation rkemper Excel Worksheet Functions 1 December 22nd 05 06:36 PM
Ignoring Time in a Date Time Calculation nmp Excel Worksheet Functions 3 November 23rd 05 08:32 PM
time calculation with military time Ron Thetford Excel Worksheet Functions 8 July 29th 05 07:24 PM


All times are GMT +1. The time now is 12:53 AM.

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

About Us

"It's about Microsoft Excel"