Help needed converting minutes and seconds

philippa0212

New Member
Joined
Jul 27, 2007
Messages
3
Hi

I need to convert a number such as 034555

ie 3 minutes 45 seconds 55 milliseconds

into seconds ie 225.55 seconds

Anyone got any ideas? The only way I can do it is to separate the number across columns which I specifically didn't want to do.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Works great THANKS, is there anyway to action that into just one column, ie automatically converts it when the time is typed.
 
Upvote 0
Yes there is, but this involves VBA. If you right-click on the sheet tab name where you want this to happen, choose View Code and then paste the following code into the worksheet module that will open:

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Change(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)
<SPAN style="color:#00007F">Dim</SPAN> s <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
<SPAN style="color:#00007F">If</SPAN> Target.Count > 1 <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
<SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> Intersect(Target, Range("A:A")) <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN>
    Application.EnableEvents = <SPAN style="color:#00007F">False</SPAN>
    s = Format(Target.Value, "000000")
    Target.Value = (CDbl(Right$(s, 2)) / 100) + CDbl(Mid$(s, Len(s) - 3, 2)) + (CDbl(Left$(s, Len(s) - 4)) * 60)
    Application.EnableEvents = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

This will automatically cahnge the value enetered into the A column from format "034555" say to its respective value in seconds (ie 225.55 in this case). Note that there is hardly any error checking involved here, so if somebody were to entrer text instead (ray "Richard" for example) then the code will bug out and report an error. Let me know what you think.
 
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,186
Members
448,554
Latest member
Gleisner2

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