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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,367
Office Version
  1. 365
Platform
  1. Windows
James

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

Eyeson15

Board Regular
Joined
Apr 30, 2015
Messages
201
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

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
18,144
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
ADVERTISEMENT
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

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,367
Office Version
  1. 365
Platform
  1. Windows
Perhaps.
Code:
    aaa = TimeSerial(Range("A1").Value, 0, 0) - TimeSerial(0, 10, 0)
 
Upvote 0

Eyeson15

Board Regular
Joined
Apr 30, 2015
Messages
201
ADVERTISEMENT
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

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
18,144
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,350
Code:
Dim xVal as Date

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

MsgBox xVal
 
Last edited:
Upvote 0

Forum statistics

Threads
1,196,027
Messages
6,012,954
Members
441,740
Latest member
abaz21

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
Top