View Single Post
 
Old 08-21-2014, 09:29 PM
excelledsoftware excelledsoftware is offline Windows 7 64bit Office 2003
IT Specialist
 
Join Date: Jan 2012
Location: Utah
Posts: 455
excelledsoftware will become famous soon enough
Default

This seems to work
Code:
Option Explicit
Sub ConvertStringToTime()
  'Converts a string into a useable decimal type format
  Dim CheckRow As Long, CheckString As String, FinalString As String
  Dim HourString As String, MinuteString As String, TotalRows As Long
  Dim TimeResult As String, UseColumn As String, ResultColumn As String
  Dim MinuteConvert As Single, BadData As Variant, x As Integer
  
    BadData = Array(" ", "H", "M", "h", "m", ",")
    TotalRows = Range("A50000").End(xlUp).Row
    UseColumn = "A" 'Change this to whatever column your data is in
    ResultColumn = "B" 'Change this to whatever Column you want the result.
    
    
    TotalRows = Range(UseColumn & "50000").End(xlUp).Row
    
      For CheckRow = 2 To TotalRows 'Start at 2 if you have headers otherwise change to 1
        CheckString = Range(UseColumn & CheckRow).Value
        'Separate hours and minutes
        HourString = Mid(CheckString, 1, InStr(1, CheckString, ",") - 1)
        MinuteString = Mid(CheckString, InStr(1, CheckString, ","))
        'Remove unusable data
        For x = 0 To UBound(BadData)
          HourString = Replace(HourString, BadData(x), "")
          MinuteString = Replace(MinuteString, BadData(x), "")
        Next x
        
        MinuteConvert = 100 / (60 / MinuteString)
        FinalString = HourString & "." & MinuteConvert
        
        'Using string to keep decimal points down
        Range(ResultColumn & CheckRow).Value = FinalString
      Next CheckRow
      
      MsgBox "Complete"
       
End Sub
Remember to set the 2 columns in the code to what you need and change the start row if you need to.

Last edited by excelledsoftware; 08-21-2014 at 09:30 PM. Reason: comment typo
Reply With Quote