Taking minutes from date time cell in VB

rwrichard1

New Member
Joined
Feb 12, 2018
Messages
6
Hi,

I have a cell with the following in it:

20/01/2018 02:03:00

I am using VB and calling for the Hour value like this...

Code:
UserFrom5.TextBox2 = WorksheetFunction.Text(Sheet6.Cells(a, 4), "hh")

This gives me 02. Perfect... exactly what I want.

How do I get the Minutes though?

Code:
UserFrom5.TextBox2 = WorksheetFunction.Text(Sheet6.Cells(a, 4), "hh:mm")

The above gives me 02:03... but

Code:
UserFrom5.TextBox2 = WorksheetFunction.Text(Sheet6.Cells(a, 4), "mm")

gives me 01... which I assume is the month instead.

I tried Nn, nn etc, but it doesn't work.

I tried...

Code:
UserFrom5.TextBox2 = Minute((Sheet6.Cells(a, 4))

But this gives me 3... and I want 03.

Please Help...?

Thanks



[TABLE="width: 111"]
<tbody>[TR]
[TD="align: right"][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Alternatives:

Code:
UserFrom5.TextBox2 = Format((Sheet6.Cells(a, 4).Value * 24) Mod 24, "00")
UserFrom5.TextBox2 = Format((Sheet6.Cells(a, 4).Value * 1440) Mod 60, "00")

WBD
 
Upvote 0
Thanks for having a look WBD. Unfortunately, the alternatves still do not give the minutes for 20/01/2018 01:00:00 Could it have something to do with the fact I have a double space after the year before the time? If I ask for hh:mm then it works absolutely fine, giving me the full time from the cell.. if I ask for hh.. it works fine giving me the hours... its just the minutes I cant seem to suss... really confusing me now.
 
Upvote 0
I've fixed it by doing this... No idea why I had to, but if it works...

Code:
UserForm5.TextBox2 = WorksheetFunction.Text(Sheet6.Cells(a, 4), "hh")
getseconds = WorksheetFunction.Text(Sheet6.Cells(a, 4), "hh:mm")
UserForm5.TextBox3 = Format(getseconds, "nn")
 
Upvote 0
I forgot about DatePart which might be useful in future:

Code:
UserForm5.TextBox2 = DatePart("h", Sheet6.Cells(a, 4).Value)
UserForm5.TextBox3 = DatePart("n", Sheet6.Cells(a, 4).Value)

WBD
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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