Userform Label time format error

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,493
Office Version
  1. 2016
Platform
  1. Windows
Hi all

So, I have this code pasted into a worksheet that will 'force' any times entered to be shown as mm:ss

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("F3:AE2000")) Is Nothing Then
    If Target.Value < 0 Or Target.Value > 1 And Target.NumberFormat <> "h:mm" Then Exit Sub
        Application.EnableEvents = False
        Target.Value = Target.Value / 60
        Target.NumberFormat = "mm:ss"
        Application.EnableEvents = True
    End If
End Sub

these times are then copied/pasted into the "Data" sheet and are displayed also as H:mm format.

However when I use these times as part of a UserForm instead of showing for example 05:26, I get times like 12:26 even though I have formatted the code in the UserForm to show the time as mm:ss like this

VBA Code:
Label39.Caption = Format(Worksheets("Data").Range("H1").Value, "mm:ss")

If I change this format to H:mm:ss I do get the correct value, for example 0:05:26

Any idea why this happens?

Thanks in advance

any ideas why this happens
 

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)

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,493
Office Version
  1. 2016
Platform
  1. Windows
After looking around here and good old Google I managed to get this to work..

VBA Code:
Label55.Caption = Worksheets("Data").Range("P1").Text
 

Forum statistics

Threads
1,140,925
Messages
5,703,208
Members
421,282
Latest member
hogie

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