Search code examples
excelreplaceexcel-formulacellbackslash

Excel - Replace " / " character within non-formula cells


For example i have two cells

A1: =1/2
A2: /abc

I want to replace / char in second cell with something else without changing first cell which contains formula. Final result should be like this

A1: = 1/2
A2: #abc

Solution

  • Select your cells and run:

    Sub dural()
        Dim r As Range
        For Each r In Selection
            If Not r.HasFormula Then
                r = Replace(r.Text, "/", "#")
            End If
        Next r
    End Sub