[Solved] Reversing a number in a string


this will iterate column A and reverse all numbers found:

Sub FLIPNUM()

    With Worksheets("Sheet1")
        Dim rngarr As Variant
        rngarr = .Range(.Cells(1, 1), .Cells(.Rows.Count, 1).End(xlUp)).Value

        Dim i As Long
        For i = LBound(rngarr, 1) To UBound(rngarr, 1)
            Dim str() As String
            str = Split(rngarr(i, 1))

            Dim j As Long
            For j = 0 To UBound(str)
                If IsNumeric(str(j)) Then
                    str(j) = StrReverse(str(j))
                End If
            Next j
            rngarr(i, 1) = Join(str, " ")
        Next i
        .Range(.Cells(1, 1), .Cells(.Rows.Count, 1).End(xlUp)).Value = rngarr
    End With

End Sub

or as a function:

Public Function ReverseNum(rng As Range) As String
    If rng.Cells.Count > 1 Then Exit Function
    Dim str() As String
    str = Split(rng.Value)

    Dim j As Long
    For j = 0 To UBound(str)
        If IsNumeric(str(j)) Then
            str(j) = StrReverse(str(j))
        End If
    Next j
    ReverseNum = Join(str, " ")
End Function

enter image description here

4

solved Reversing a number in a string