Pancake_Effect
asked on
Excel: Insert colon in military time column?
We have a excel work sheet, there is a very long column that states the time for an event. We need the time in the format below:
Original
hhmm
Needed Change
hh:mm
This is my original code below for other changes, if it could be added for range G:G for example that would be great!
Thanks!
Original
hhmm
Needed Change
hh:mm
This is my original code below for other changes, if it could be added for range G:G for example that would be great!
Thanks!
Sub replaceText()
Dim c As Range, rg As Range
Application.ScreenUpdating = False
Set rg = Intersect(Range("A:A"), ActiveSheet.UsedRange)
For Each c In rg.Cells 'Only search column L
Select Case c.Value
Case "B" 'Old value
c.Value = 3 'New value
Case "BAP" 'Old value
c.Value = 3 'New value
Case "BB" 'Old value
c.Value = 3 'New value
Case Else 'Do nothing
End Select
Next
Application.ScreenUpdating = False
Set rg = Intersect(Range("C:C"), ActiveSheet.UsedRange)
For Each c In rg.Cells 'Only search column L
Select Case c.Value
Case "M" 'Old value
c.Value = "Male" 'New value
Case "F" 'Old value
c.Value = "Female" 'New value
Case Else 'Do nothing
End Select
Next
Set rg = Intersect(Range("D:D"), ActiveSheet.UsedRange)
rg.NumberFormat = "@"
For Each c In rg.Cells 'Only search column D (ARADMDT)
If c <> "" Then c.Value = Mid(c.Value, 5, 2) & Right(c.Value, 2) & Left(c.Value, 4) 'Change date from yyyymmdd to ddmmyyyy
Next
End Sub
ASKER
I did a cut and paste from the original document. (Attached) This is what an example of what their work currently is.
The sheet of changes states it needs to be changed to hh:mm. That's all it said that is needing to be changed. So I'm assuming just a colon is needed.
times.xlsx
The sheet of changes states it needs to be changed to hh:mm. That's all it said that is needing to be changed. So I'm assuming just a colon is needed.
times.xlsx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked flawlessly, thank you so much!
ASKER
Say I have one last question I forgot to ask before I marked this question as answered, is there a way to add a zero for example 06:00 instead of 6:00? Thanks!
The cells are actually converted to time values. How they display can be specified with the cell format. So, you may want to use the custom format
hh:mm
after running the macro.
cheers, teylyn
hh:mm
after running the macro.
cheers, teylyn
are the time values text or numbers? How do times between midnight and 1 am show? With leading zeroes?
It might be useful to see a few samples, including values just after midnight.
cheers, teylyn