• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macro to remove character to remove list of characters

Can this be changed to remove a list of characters? often I am having to call it 2 or 3 times with different characters that I need to remove.

Thanks

Code:
Sub RemoveChar()
Const char As String * 1 = "]" 'change to suit
Dim LR As Long, i As Long, x As Variant
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    With Range("I" & i)
        x = Split(.Value)
        x(UBound(x)) = Replace(x(UBound(x)), char, vbNullString)
        .Value = Join(x)
    End With
Next i
End Sub
 
Hi Tim ,

Try this :
Code:
Sub RemoveChar()
Dim char As Variant, x As Variant
Dim LR As Long, i As Long, j As Long
 
char = Array("]", "{", "%")        '  Change this to suit
LR = Range("A" & Rows.Count).End(xlUp).Row
 
For i = 1 To LR
    With Range("I" & i)
        x = Split(.Value)
        For j = LBound(char) To UBound(char)
            x(UBound(x)) = Replace(x(UBound(x)), char(j), vbNullString)
        Next
        .Value = Join(x)
    End With
Next i
End Sub
Narayan
 
Back
Top