I will try this and report back. This is a significant time spent so thank you very much for your help.Cubist has already provided a Function version but since you have provided information for running a macro try this on a copy of your workbook.
At this stage it is outputting to the next empty column in the spreadsheet.
If you have validated the output and want it to overwrite column L that is a simple modification.
VBA Code:Sub ConvertStringToTime() Dim ws As Worksheet Dim rngTimeTxt As Range, arr As Variant Dim rngOut As Range Dim splitTime As Variant, partTime As String Dim rowHdg As Long, i As Long, j As Long Dim hrs As Long Dim mins As Long Dim secs As Long Set ws = ActiveSheet rowHdg = 5 With ws Set rngTimeTxt = .Range(.Cells(rowHdg + 1, "L"), .Cells(Rows.Count, "L").End(xlUp)) arr = rngTimeTxt.Value End With Set rngOut = ws.Cells(rowHdg, Columns.Count).End(xlToLeft).Offset(1, 1) For i = 1 To UBound(arr) hrs = 0 mins = 0 secs = 0 splitTime = Split(Trim(arr(i, 1)), " ") For j = 0 To UBound(splitTime) partTime = splitTime(j) Select Case True Case UCase(partTime) Like "HOUR*" hrs = Val(splitTime(j - 1)) Case UCase(partTime) Like "MINUTE*" mins = Val(splitTime(j - 1)) Case UCase(partTime) Like "SECOND*" secs = Val(splitTime(j - 1)) Case Else ' do nothing End Select Next j arr(i, 1) = 24 * TimeSerial(hrs, mins, secs) Next i 'rngOut.Offset(-1).Value = "Est Duration (hrs)" <--- Leave heading for now, easier to rerun rngOut.Resize(UBound(arr)) = arr End Sub
Just out of curiosity, you speak of a simple modification to overright the origianl data in Column L. I am doing it by cutting and inserting into Column L. is there another way to incorporate inside this?Cubist has already provided a Function version but since you have provided information for running a macro try this on a copy of your workbook.
At this stage it is outputting to the next empty column in the spreadsheet.
If you have validated the output and want it to overwrite column L that is a simple modification.
VBA Code:Sub ConvertStringToTime() Dim ws As Worksheet Dim rngTimeTxt As Range, arr As Variant Dim rngOut As Range Dim splitTime As Variant, partTime As String Dim rowHdg As Long, i As Long, j As Long Dim hrs As Long Dim mins As Long Dim secs As Long Set ws = ActiveSheet rowHdg = 5 With ws Set rngTimeTxt = .Range(.Cells(rowHdg + 1, "L"), .Cells(Rows.Count, "L").End(xlUp)) arr = rngTimeTxt.Value End With Set rngOut = ws.Cells(rowHdg, Columns.Count).End(xlToLeft).Offset(1, 1) For i = 1 To UBound(arr) hrs = 0 mins = 0 secs = 0 splitTime = Split(Trim(arr(i, 1)), " ") For j = 0 To UBound(splitTime) partTime = splitTime(j) Select Case True Case UCase(partTime) Like "HOUR*" hrs = Val(splitTime(j - 1)) Case UCase(partTime) Like "MINUTE*" mins = Val(splitTime(j - 1)) Case UCase(partTime) Like "SECOND*" secs = Val(splitTime(j - 1)) Case Else ' do nothing End Select Next j arr(i, 1) = 24 * TimeSerial(hrs, mins, secs) Next i 'rngOut.Offset(-1).Value = "Est Duration (hrs)" <--- Leave heading for now, easier to rerun rngOut.Resize(UBound(arr)) = arr End Sub
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.Thank you Alex (and Cubist) for the help, the vba code is working well!