Reversing a format ...

adambc

Board Regular
Joined
Jan 13, 2020
Messages
174
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 ...
 

Some videos you may like

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

adambc

Board Regular
Joined
Jan 13, 2020
Messages
174
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
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?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,263
Office Version
  1. 365
Platform
  1. Windows
Have you tried using TimeValue and multiplying by 24*60?
 

adambc

Board Regular
Joined
Jan 13, 2020
Messages
174
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,263
Office Version
  1. 365
Platform
  1. Windows
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
 

adambc

Board Regular
Joined
Jan 13, 2020
Messages
174
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
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 ...
 

Watch MrExcel Video

Forum statistics

Threads
1,126,888
Messages
5,621,417
Members
415,839
Latest member
Pollydooner

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