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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

philippa0212

New Member
Joined
Jul 27, 2007
Messages
3
Works great THANKS, is there anyway to action that into just one column, ie automatically converts it when the time is typed.
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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.
 

Forum statistics

Threads
1,181,730
Messages
5,931,707
Members
436,799
Latest member
BasOo

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