Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Gum Gum is offline
external usenet poster
 
Posts: 30
Default Adding Time to a variable in Excel VBA

I have a time string:
mytime= Format(Now(), "hh:mm:ss AMPM")
I need to add "00:00:40" to mytime
How can I do so and avoid mismatching.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Adding Time to a variable in Excel VBA

t = Now() + TimeValue("00:00:40")
mytime = Format(t, "hh:mm:ss AMPM")

--
Gary''s Student - gsnu200822


"Gum" wrote:

I have a time string:
mytime= Format(Now(), "hh:mm:ss AMPM")
I need to add "00:00:40" to mytime
How can I do so and avoid mismatching.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Adding Time to a variable in Excel VBA

Hi Gum,

In your sample mytime is a string variable.
So you can not add any DateTime value to it.
This has to be done before the Format function is used.

Gary's version works fine but you cab also use:

mtyime = Format(DateAdd("s", 40, Now()), "hh:mm:ss AMPM")

HTH,

Wouter
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Adding Time to a variable in Excel VBA

The Format function produces a human readable string of text (in Variant
form), not a date/time. Dates and times in VB are actually stored in as a
Double... the whole number part represents the number of days since "date
zero" (which is 12/30/1899) and the decimal part represents the fraction of
a 24-hour day; so formatting the Now function does nothing to aid you in
your goal. VB provides a rich set of Date manipulation functions which you
might want to familiarize yourself with in the help files (use "date
functions", with the quotes, when searching the VBA editor's help files).
Now, to answer your question, I would use this...

mytime = DateAdd("s", 40, Now)

--
Rick (MVP - Excel)


"Gum" wrote in message
...
I have a time string:
mytime= Format(Now(), "hh:mm:ss AMPM")
I need to add "00:00:40" to mytime
How can I do so and avoid mismatching.


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
Run-Time error '91': Object variable of With block variable not set jammin1911 Excel Programming 3 June 6th 06 06:36 PM
Run-time Error'91: Object variable or With block variable not set DynamiteSkippy Excel Programming 4 September 26th 05 07:47 AM
Adding time in Excel MovieSchedules Excel Worksheet Functions 1 January 31st 05 10:18 AM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
Adding time in Excel tahirab Excel Worksheet Functions 1 November 10th 04 09:47 PM


All times are GMT +1. The time now is 11:40 PM.

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"