Reversing a concatenation ...

adambc

Active Member
Joined
Jan 13, 2020
Messages
373
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I have a UserForm with two TextBoxes (txtReportedTimeHours & txtReportedTimeMins) which are written to a single column (Reported Time) when I Save the UserForm using ...

VBA Code:
Cells(m + 1),10.value = txtReportedTimeHours & ":" & txtReportedTimeMins

... where the m in Cells(m + 1, 10) is the next row - THIS ALL WORKS FINE

I now want to read Reported Time back into the TextBoxes ie separating out HH:MM into HH & MM but can't work out how to read left of : into txtReportedTimeHours and righ of : into txtReportedTimeMins ...

Can anyone help please?

Thanks ...
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Here is a little example to show you how to do that:
VBA Code:
Sub Test()

    Dim str As String
    Dim hr As String
    Dim min As String
    
    str = "10:43"
    
    hr = Left(str, InStr(str, ":") - 1)
    min = Mid(str, InStr(str, ":") + 1)
    
    MsgBox "Hour = " & hr & vbCrLf & "Min = " & min
    
End Sub
 
Upvote 0
.. another way
VBA Code:
Sub Test2()
    Dim str As String, hr As String, min As String
    
    str = "10:43"
    hr = Split(str, ":")(0)
    min = Split(str, ":")(1)
    MsgBox "Hour = " & hr & vbCrLf & "Min = " & min
End Sub
 
Upvote 0
Unfortunately none of the suggestions worked, but I've changed the way "hh:mm" is created by using a single SpinButton writing to a single TextBox using ...

VBA Code:
TextBox1 = Format(SpinButton1 / 24 / 60, "hh:mm")

... and then saving the result to my underlying table ...

However, when I read the record back in, TextBox1 is populated correctly, but when I use the SpinButton, it defaults to its Value as the start point rather than the value in TextBox1 ...

I've tried SpinButton1 = Textbox1 (with and without .Value) but I get a mismatch 13 error.

Hope that makes sense?

Any ideas?

Thanks ...
 
Upvote 0
Unfortunately none of the suggestions worked, but I've changed the way "hh:mm" is created by using a single SpinButton writing to a single TextBox using ...

VBA Code:
TextBox1 = Format(SpinButton1 / 24 / 60, "hh:mm")

... and then saving the result to my underlying table ...

However, when I read the record back in, TextBox1 is populated correctly, but when I use the SpinButton, it defaults to its Value as the start point rather than the value in TextBox1 ...

I've tried SpinButton1 = Textbox1 (with and without .Value) but I get a mismatch 13 error.

Hope that makes sense?

Any ideas?

Thanks ...
IGNORE ME - had the SpinButton property values set wrong - all good now!!!
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,937
Members
449,094
Latest member
teemeren

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