检查并删除连续的ips /数字

时间:2018-01-11 19:06:12

标签: javascript php excel

您需要一个excel公式才能从列出的列中删除文本文件中的连续ips。

现在怎么样:

 - 141.101.x.18,
   141.105.x.161,
   141.105.x.162,
   141.105.x.163,
   141.105.x.185,
   141.105.x.204,
   141.105.x.205,
   141.105.x.206,

我是怎么需要的:

141.101.x.18,
141.105.x.185

它可能是excel,php,javascript我只需要用大量数据清理一个列表。

1 个答案:

答案 0 :(得分:-1)

的Excel

使用 A 列中的数据尝试这个简短的VBA宏:

Sub dataKiller()
    Dim i As Long, N As Long, rDel As Range
    Set rDel = Nothing
    N = Cells(Rows.Count, "A").End(xlUp).Row

    For i = N To 2 Step -1
        If vl(Cells(i, 1)) = vl(Cells(i - 1, 1)) + 1 Then
            If rDel Is Nothing Then
                Set rDel = Union(Cells(i, 1), Cells(i - 1, 1))
            Else
                Set rDel = Union(rDel, Cells(i, 1), Cells(i - 1, 1))
            End If
        End If
    Next i

    rDel.Delete shift:=xlUp
End Sub

Public Function vl(s As String) As Long
    vl = CLng(Replace(Split(s, ".")(3), ",", ""))
End Function

在:

enter image description here

之后:

enter image description here

vl() UDF提取每个值中的最后一个数字。