I have imported data into excel and one column contains the military time.
It is displayed as below. How can I insert a ":" for the entire column in
the correct place. I have not been able to do it through Format-Cells
menu.
160526 16:05:26
90928 9:09:28
92155 9:21:55
110101 11:01:01
Okay, I think you are asking for a way to change the data in the same column
it is being placed in. You won't be able to do that with spreadsheet
formulas; so, if you are up for a macro solution, put the following code in
the code window for the sheet you want it to operate on...
Sub FixColumnTime()
Dim R As Range
Dim C As Range
Set R = Range("C:C")
Application.EnableEvents = False
For Each C In R
If C.Text = "" Then
Exit For
ElseIf IsNumeric(C.Text) Then
C.Value = TimeSerial(Int(C.Value / 10000), _
Int((C.Value Mod 10000) / 100), _
C.Value Mod 100)
End If
Next
Application.EnableEvents = True
End Sub
Here, I have set the subroutine to operate on Column "C"... change the Set
statement above to reflect the column you actually want to change. As
constructed, the code will execute down the column, changing pure numbers
only (so you can run the macros over already converted value without
affecting them), and will stop executing at the first empty cell it
encounters. To execute this code (once you have pasted it into your
worksheet), select Tools/Macro/Macros from the spreadsheet's menu (or press
Alt+F8), select the FixColumnTime macro and click the Run button.
Rick
Rick