Home » excel » find – Remove some number in a excel cell

find – Remove some number in a excel cell

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have a series (column) of numbers

      A

1  1209999
2  158999 
3  1329999
4  139999

i want to remove all the 9 at the end of a cell , so the number 1209999 would be 120 and the number 158999 would be 158 is that possible ?

How to&Answers:

If you need to remove all “9” from cell, use =SUBSTITUTE(A1,"9","")

If you need to remove only “9” in the end of string, use this tiny UDF:

Function DelEnd9(x As String)
    DelEnd9 = x
    If Len(x) = 0 Then Exit Function
    If Right(x, 1) <> "9" Then Exit Function        
    DelEnd9 = DelEnd9(Left(x, Len(x) - 1))
End Function

and call it like this: =DelEnd9(A1)

enter image description here

Answer:

Try this small macro:

Sub NineKiller()
    Dim N As Long, I As Long, v As String, L As Long
    N = Cells(Rows.Count, "A").End(xlUp).Row
    For I = 1 To N
        v = Cells(I, "A").Text
        L = Len(v)
        For j = L To 1 Step -1
            ch = Right(v, 1)
            If ch = "9" Then
                v = Mid(v, 1, Len(v) - 1)
            Else
                GoTo getanother
            End If
        Next j
getanother:
        If Len(v) <> Len(Cells(I, "A").Text) Then
            Cells(I, "A").Value = v
        End If
    Next I
End Sub

Answer:

Give this formula a try (enter into B1 and drag down):

=REPLACE(A1,MIN(FIND({“999999ß”,”99999ß”,”9999ß”,”999ß”,”99ß”,”9ß”},A1&”ß999999ß”)),8,””)