Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 276
Default Adding time by a Numerical Value

I have a cell with a format of "hh:mm AM/PM" and
another cell in a numerical format of "0.75".

I want to using VBA, add the numerical value to the time to create a new
time, such as:

A1= 7:30 AM
B1 = 0.75 ' 45mins
C1= 8:15 AM ' Result.

I cannot seem to get the correct syntax to add the value to give me the
desired result.

If i format the numerical value as "hh:mm" it changes from 0.75 to 18:00 ?

How can i do this:

Corey....


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Adding time by a Numerical Value

I have a cell with a format of "hh:mm AM/PM" and
another cell in a numerical format of "0.75".

I want to using VBA, add the numerical value to the time to create a new
time, such as:

A1= 7:30 AM
B1 = 0.75 ' 45mins
C1= 8:15 AM ' Result.

I cannot seem to get the correct syntax to add the value to give me the
desired result.

If i format the numerical value as "hh:mm" it changes from 0.75 to 18:00 ?

How can i do this:

Corey....



This worked for me:

Sub AddTimeAsNumber()
Dim num As Integer
num = Hour(Range("A1")) * 60 _
+ Minute(Range("A1")) _
+ Range("B1") * 60
Range("C1") = Format(WorksheetFunction.RoundDown(num / 60, 0) _
& ":" & num Mod 60, "h:mm\ AM/PM")
End Sub

.... but there's probably a more elegant way!

Ian

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Adding time by a Numerical Value

If i format the numerical value as "hh:mm" it changes from 0.75 to 18:00 ?

That's because 18:00 (6pm) is three-quarters of the way through the day.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default Adding time by a Numerical Value

Hello, you can try this:

Sub timeval()

Range("C1").Value = Range("A1") + TimeSerial(0, Minute("12:" &
Range("B1") * 60), 0)

End Sub


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 276
Default Adding time by a Numerical Value

Thanks Ian.

Perfect.
"IanKR" wrote in message
...
I have a cell with a format of "hh:mm AM/PM" and
another cell in a numerical format of "0.75".

I want to using VBA, add the numerical value to the time to create a new
time, such as:

A1= 7:30 AM
B1 = 0.75 ' 45mins
C1= 8:15 AM ' Result.

I cannot seem to get the correct syntax to add the value to give me the
desired result.

If i format the numerical value as "hh:mm" it changes from 0.75 to 18:00
?

How can i do this:

Corey....



This worked for me:

Sub AddTimeAsNumber()
Dim num As Integer
num = Hour(Range("A1")) * 60 _
+ Minute(Range("A1")) _
+ Range("B1") * 60
Range("C1") = Format(WorksheetFunction.RoundDown(num / 60, 0) _
& ":" & num Mod 60, "h:mm\ AM/PM")
End Sub

... but there's probably a more elegant way!

Ian





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Adding time by a Numerical Value

Hello, you can try this:

Sub timeval()

Range("C1").Value = Range("A1") + TimeSerial(0, Minute("12:" &
Range("B1") * 60), 0)

End Sub


!!

I knew somebody would come up with a slicker formula then mine. I didn't
know about TimeSerial - equivalent to DateSerial, of course.

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
Adding a Leter to a Numerical Value on Exit Corey ....[_2_] Excel Programming 3 July 7th 08 06:28 AM
Giving letters a numerical value, then adding the total. Richard in Stockholm Excel Discussion (Misc queries) 17 April 9th 08 05:01 PM
Adding up non numerical values Wooster New Users to Excel 3 September 23rd 07 01:03 AM
Adding numbers to an incomplete numerical list hana Excel Discussion (Misc queries) 17 January 11th 07 09:46 PM


All times are GMT +1. The time now is 12:30 PM.

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

About Us

"It's about Microsoft Excel"