How do I turn a column of data into times... via macros

Hyflex

New Member
Joined
Mar 28, 2011
Messages
40
How is the best way to change my data into a time, I was thinking of making a macro to put a semi-colon after two numbers & then to format the column as: h:mm but I'm sure there must be a faster and better way to do it. If I could insert a semi-colon in the middle (after two numbers) I would be able to do the rest.

Please help :)

Raw Data:
Code:
0500
0530
1205
0240
0315
0345
0420


The end result I want is:
Code:
5:00
5:30
12:05
2:40
3:15
3:45
4:20
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
If your Raw data is formatted as Text

Code:
=VALUE(LEFT(A1,2)&":"&RIGHT(A1,2))

Format as time hh:mm
 
Upvote 0
A macro:

Code:
Sub Test()
    Dim Cell As Range
    With ActiveSheet
        For Each Cell In .Range("A1:A" & .Range("A" & .Rows.Count).End(xlUp).Row)
            Cell.NumberFormat = "hh:mm"
            Cell.Value = TimeValue(WorksheetFunction.Replace(Cell.Value, 3, 0, ":"))
        Next Cell
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,750
Members
452,940
Latest member
rootytrip

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