change integer to time by VBA

Eyeson15

Board Regular
Joined
Apr 30, 2015
Messages
201
Hello everyone
I'm going little nuts here

A1 has value 15 in it. (integer, no decimals)
I need VBA to dim this value as hh:mm:ss and then subtract 10minutes from it

How close am I?

Code:
Sub timechange
Dim aaa as Date
aaa = Range("A1").value + Timeserial(0,-10,0)

Thank you in advance,

James
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
James

What time does the 15 in A1 represent? 15 hours? minutes? seconds?
 
Upvote 0
James

What time does the 15 in A1 represent? 15 hours? minutes? seconds?


Hi there

ahhh 15 represent 3pm. 16 represents 4pm and so on.

so if A1 is 15 then I need 3pm - 10 minutes to continue working with other macros
 
Upvote 0
Hi there

ahhh 15 represent 3pm. 16 represents 4pm and so on.

so if A1 is 15 then I need 3pm - 10 minutes to continue working with other macros
Does this do what you want?
Code:
Sub Take10()
Const T As Variant = 10
aaa = Range("A1").Value / 24 - TimeSerial(0, T, 0)
MsgBox Format(aaa, "hh:mm:ss AM/PM")
End Sub
 
Upvote 0
Perhaps.
Code:
    aaa = TimeSerial(Range("A1").Value, 0, 0) - TimeSerial(0, 10, 0)
 
Upvote 0
Does this do what you want?
Code:
Sub Take10()
Const T As Variant = 10
aaa = Range("A1").Value / 24 - TimeSerial(0, T, 0)
MsgBox Format(aaa, "hh:mm:ss AM/PM")
End Sub

Oh god you are a heaven sent because that worked perfectly. I can take it from here but thank you so much.

I will think about you before I sleep tonight.

James
 
Upvote 0
Oh god you are a heaven sent because that worked perfectly. I can take it from here but thank you so much.

I will think about you before I sleep tonight.

James
You are welcome - thanks for the reply.
 
Upvote 0
Code:
Dim xVal as Date

xVal = TimeValue((Range("A1").Value - 1) & ":50:00")

MsgBox xVal
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,595
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top