Oh, yeah, sorry about that. Try this instead (I'll explain the changes below):
Sub test()
' Varables for workbook and worksheet
Dim wb As Workbook
Set wb = ThisWorkbook
Dim ws As Worksheet
Set ws = wb.Worksheets("Sheet1")
' Set range to process
' You'll need to adjust the columns to meet your needs
Dim lastrow As Long
lastrow = ws.Range("A1048576").End(xlUp).Row
Dim rng As Range
Set rng = ws.Range("A1:A" & lastrow)
Dim cl As Variant ' Used to handle cell value
Dim strAMT As String ' Used to capture original amount for text operations
Dim dblOrig As Variant
Dim dblNew As Variant
Dim splitter As String
Dim lngSTART As Long
Dim lngOrigLEN As Long
Dim lngNewLEN As Long
' For each cell in the range
For Each cl In rng
If Not cl.Value = "" Then ' NEW
Select Case Right(cl.Value, 6)
Case "USC/LB"
' Do Nothing
Case "USD/MT"
' Perform Caluculation
Select Case True
Case (InStr(cl.Value, "+")) > 0
splitter = "+"
lngSTART = InStr(cl.Value, "+") + 1
Case (InStr(cl.Value, "-")) > 0
splitter = "-"
lngSTART = InStr(cl.Value, "-") + 1
End Select
' Get amount value
strAMT = Split(Split(cl.Value, " ")(1), splitter)(1)
dblOrig = CDbl(strAMT)
lngOrigLEN = Len(dblOrig)
' Divide and round
dblNew = Round(dblOrig / 22.046, 2)
' Convert back to string and append 0's
dblNew = CStr(dblNew) & "00"
lngNewLEN = Len(dblNew)
' Replace Text
cl.Value = Replace(Replace(cl.Value, strAMT, dblNew), "USD/MT", "USC/LB")
' Bolds and colors must be applied last or will affect whole cell
' Bold first two characters
With cl.Characters(start:=1, Length:=2)
.Font.Bold = True
End With
' Red
With cl.Characters(start:=lngSTART, Length:=lngNewLEN)
.Font.ColorIndex = 3
End With
' Bold USD/...
With cl.Characters(start:=Len(cl.Value) - 6, Length:=6)
.Font.Bold = True
End With
End Select
End If ' NEW
Next cl
Set ws = Nothing
Set wb = Nothing
End Sub
So, all I did was add a check for empty cells right inside the for/each loop. If the cell is empty, it just moves to the next cell.
for each cl in rng
if not cl.value = "" then
' rest of procedure
end if
next cl
Bookmarks