删除一个Excel单元格中的一些数字

我有一系列的数字

A 1 1209999 2 158999 3 1329999 4 139999 

我想删除一个单元格结尾的所有9,所以1209999的数字是120,158999的数字是158。

如果您需要从单元格中删除所有“9”,请使用=SUBSTITUTE(A1,"9","")

如果你需要在string末尾只删除“9”,使用这个小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 

并像这样调用它: =DelEnd9(A1)

在这里输入图像说明

试试这个小macros:

 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 

试一试这个公式(进入B1并向下拖动):

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