UserForm TextBox - Format as minutes only

Alan_P

Well-known Member
Joined
Jul 8, 2014
Messages
596
Hi Guys,

I'm absolutely stumped on what I thought would be very very easy and could do with some help please! :confused:

I've got a time value in cell A1, say 10:45. On my UserForm I've got two TextBoxes, in the first one I want to show the hour value - "10", in the second one I want to show the minute value - "45"

The hour value is easy:
Code:
TextBox1.Value = Format(Cells(1, 1).Value, "HH")

But I can't for the life of me figure out how to get the minute value in a textbox!

Any help would be very much appreciated!
Thanks,
Alan.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Alan_P

Well-known Member
Joined
Jul 8, 2014
Messages
596
hmmm never mind, the first thing I tried after I clicked post worked :rolleyes:

Code:
TextBox1.Value = Right(Format(Cells(1, 1).Value, "HH:MM"), 2)

My brain's having a lazy day :LOL:
 
Upvote 0

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
How about

Code:
TextBox1.Value = Hour(Range("A1").Value)
TextBox2.Value = Minute(Range("A1").Value)
 
Upvote 0

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,150
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
How about

Code:
TextBox1.Value = Hour(Range("A1").Value)
TextBox2.Value = Minute(Range("A1").Value)
The OP should definitely be using those functions. Just pointing out for those who do not mind using the square bracket version of Evaluate (when the cell address is fixed and non-changing), there is this compact version of your code lines...

Code:
 TextBox1.Value = Hour([A1])
 TextBox2.Value = Minute([A1])
 
Upvote 0

Forum statistics

Threads
1,190,781
Messages
5,982,870
Members
439,802
Latest member
Teiho

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