Option Explicit
Sub ReformatTimes()
Dim ws As Worksheet
Dim rng As Range
Dim cell As Range
Dim columnsToFormat As Variant
Dim col As Variant
Dim cellValue As String
Dim correctedValue As String
' Set the worksheet
Set ws = ThisWorkbook.Sheets("ecm_formatted") ' Change "Sheet1" to your sheet name
' Define the columns to format
columnsToFormat = Array("I", "J", "K", "L")
' Loop through each column
For Each col In columnsToFormat
' Set the range for the column
Set rng = ws.Range(col & "1:" & col & ws.Cells(ws.Rows.Count, col).End(xlUp).Row)
' Loop through each cell in the range
For Each cell In rng
' Check if the cell is not empty
If cell.Value <> "" Then
cellValue = cell.Value
' Correct any non-standard time formats
If InStr(cellValue, "/") > 0 Then
correctedValue = Replace(cellValue, "/", ":")
If IsDate(correctedValue) Then
' Convert the corrected time to 24-hour format
cell.Value = Format(TimeValue(correctedValue), "hh:mm")
End If
ElseIf IsDate(cellValue) Then
' Convert the time to 24-hour format
cell.Value = Format(TimeValue(cellValue), "hh:mm")
End If
End If
Next cell
Next col
End Sub