Thread: [Solved] Help with Macro error
View Single Post
 
Old 12-05-2016, 12:28 PM
NoSparks NoSparks is offline Windows 7 64bit Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 842
NoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of light
Default

Hmmm... you're selecting column A for the replacements and then formatting column B to "0.00" ???

Assuming the alpha cost codes are in column A and you want the actual cost in the adjacent column B cell, this will do it.
Perhaps there's something you can use or adapt.

Code:
Sub ConvertToCost()

Dim cel As Range
Dim str As String

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

On Error Resume Next    'in case value doesn't convert

For Each cel In Sheets("Sheet1").Range("A2:A" & Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row)
    If cel.Value <> "" And Not IsNumeric(cel.Value) Then
        str = LCase(Trim(cel.Value))
        cel.Offset(0, 1).Value = Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace _
              (str, "c", 1), "h", 2), "a", 3), "r", 4), "l", 5), "e", 6), "s", 7), "t", 8), "o", 9), "n", 0) / 100
        cel.Offset(0, 1).NumberFormat = "0.00"
    End If
Next cel

On Error GoTo 0         'turn error check back on

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub
Reply With Quote