View Single Post
 
Old 07-26-2018, 07:51 AM
NoSparks NoSparks is offline Windows 7 64bit Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

Assumes data in column A starting in row 2.
Writes result to adjacent column B cell.
Probably not the best way. It's slow.
For all 989,899 possibilities takes 36 seconds on my computer.
Code:
Sub Convert_to_Hex()
Dim rng As Range, cel As Range
Dim i As Long, str As String, tmp As String

Application.ScreenUpdating = False

Set rng = Range("A2", Range("A" & Rows.Count).End(xlUp))
For Each cel In rng
    str = cel.Value
    
    For i = 1 To Len(str)
        Select Case Asc(Mid(str, i, 1))
            Case Is = 45    'hyphen
                tmp = tmp & "2d"
            Case Is = 48    'zero
                tmp = tmp & "30"
            Case Is = 49    'one
                tmp = tmp & "31"
            Case Is = 50    'two
                tmp = tmp & "32"
            Case Is = 51    'three
                tmp = tmp & "33"
            Case Is = 52    'four
                tmp = tmp & "34"
            Case Is = 53    'five
                tmp = tmp & "35"
            Case Is = 54    'six
                tmp = tmp & "36"
            Case Is = 55    'seven
                tmp = tmp & "37"
            Case Is = 56    'eight
                tmp = tmp & "38"
            Case Is = 57    'nine
                tmp = tmp & "39"
        End Select
    Next i
    
    cel.Offset(, 1).Value = tmp
    tmp = ""
Next cel

Application.ScreenUpdating = True

End Sub
Reply With Quote