Reversing a format ...

adambc

Active Member
Joined
Jan 13, 2020
Messages
370
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I am using a UserForm (New Record) SpinButton to populate a TIME field using ...

VBA Code:
txtReportedTime.value = Format(spnReportedTime / 24 / 60, "hh:mm")

... which works perfectly ...

But I now want to read that field back into another UserForm (Update Record) and set SpinButton.Value to the value of the field - but of course the field value is hh:mm whereas the SpinButton value is a numeric ...

Is there a way to reverse the process eg ...

VBA Code:
spnReportedTime.value = Format(txtReportedTime etc etc)

Many thamks for any help anyone can give me ...
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
No-one?

Or am I chasing something that's not possible ...

Just to qualify SpinButton is set up with ...

Max 1440 (24 hrs * 60 mins)
Min 1
Small Change 10

... so 12 noon = 720, from which txtReportedTime is populated with 12:00 (which is the value that's then saved to the underlying column) ...

I can read this back into txtReportedTime perfectly - but I also want to be able to use 12:00 = 720 to set the SpinButton Value (rather than the SpinButton reverting to it's default Value) ...

Many thanks for any help - or clearly being told this is isn't possible?
 
Upvote 0
Have you tried using TimeValue and multiplying by 24*60?
 
Upvote 0
Have you tried using TimeValue and multiplying by 24*60?
@Norie

Not sure how that helps?

I want to convert h:mm back to a numeric (having converted a numeric to get the h:mm in the first place - see code above) ...

Thanks
 
Upvote 0
If you have a time in text format using TimeValue will convert it into a time value and then multiplying it by 24*60 will give you the time in minutes as a numeric value.

Isn't that what you wanted?
VBA Code:
Dim strTime As String

    strTime = "07:30"
    
    Debug.Print TimeValue(strTime) * 24 * 60
    
    strTime = "12:00"
    
    Debug.Print TimeValue(strTime) * 24 * 60
 
Upvote 0
If you have a time in text format using TimeValue will convert it into a time value and then multiplying it by 24*60 will give you the time in minutes as a numeric value.

Isn't that what you wanted?
VBA Code:
Dim strTime As String

    strTime = "07:30"
   
    Debug.Print TimeValue(strTime) * 24 * 60
   
    strTime = "12:00"
   
    Debug.Print TimeValue(strTime) * 24 * 60
@Norie

You're a STAR - works a treat ...

This is the actual code I've implemented ...

VBA Code:
'Set SpinButton value to Incident Time
Dim strIncidentTime As String
    strIncidentTime = txtIncidentTime
    spnIncidentTime.value = TimeValue(strIncidentTime) * 24 * 60

Many thanks ...
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,272
Members
449,075
Latest member
staticfluids

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