how to convert time eg 11:33:59 to text within a macro

oldbrewer

Well-known Member
Joined
Apr 11, 2010
Messages
11,012
hello everybody and thanks in advance - I wish to use a macro to determine present time using now() and then convert that value to text within the macro. I do not wish to use helper cells on the spreadsheet. I am using excel 2000.
 
This would work...
VBA Code:
Dim t As String
t = [TEXT(NOW(),"hh:mm:ss.000")]
MsgBox t
Note: I used 3 zeros because you did, however, you can only retrieve 2 decimal places maximum on the seconds.
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I am not very good with VBA - retired 16 years ago, 78 years old. Never used message boxes. Can I just use the middle line beginning t = ?
Thanks for trying to help. I failed with format(now(),"hh:mm:ss.000")
You don't need to use the MsgBox.
That is just there for demonstration purposes, to show what it is calculating/returning.
The "t" variable would be all that you need.
 
Upvote 0

Forum statistics

Threads
1,215,071
Messages
6,122,964
Members
449,094
Latest member
Anshu121

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