0

我在 B 列中有一个电话号码数据库(大约 50k 条记录),我想将所有以“07”开头的数字提取到同一行的 C 列中。我有这个。

          A                B
1    0113 1210012
2    07878 121213
3    01423 568741
4    07584 123123
5    0033 123456789
6    07548 1234567

我需要一种方法来创建它

          A                  B
1    0113 1210012
2                       07878 121213
3    01423 568741
4                       07584 123123
5    0033 123456789
6                       07548 1234567
4

2 回答 2

0

这应该做的工作

Sub Filter07()

Dim MyRange As Range, MyCell As Range

Set MyRange = Range([B1], Cells(Cells(ActiveSheet.Rows.Count, 2).End(xlUp).Row, 2))

For Each MyCell In MyRange

    If Left(Trim(Format(MyCell.Value, "@")), 2) = "07" Then

        MyCell(1, 2) = Trim(Format(MyCell.Value, "@"))
        MyCell = ""

    End If

Next MyCell

End Sub
于 2013-01-11T09:47:24.010 回答
0

这是一个 VBA 代码供您尝试:我使用了regexandarraylist对象。在代码对象中循环比使用它range来最小化工作表和代码之间的流量更快。另外不确定您是否只想输出重复项或唯一项。所以我只是简单地选择 ArrayList against the Dictionary。ArrayList 还允许您保持正确的位置;)

Option Explicit

Sub StartingWith07()
Dim vArray As Variant
Dim dc As Object
Dim objRegex As Object
Dim i As Integer
Dim arrList As Object

Set arrList = CreateObject("System.Collections.ArrayList")
Set objRegex = CreateObject("VBScript.RegExp")
objRegex.IgnoreCase = True
objRegex.Global = True
objRegex.Pattern = "^(07)"

'-- you can also use dynamic last row to set the range from A2
vArray = WorksheetFunction.Transpose(Sheets(1).Range("A2:A10").Value)

    For i = LBound(vArray) To UBound(vArray)
        If objRegex.Test(Trim(vArray(i))) Then
            arrList.Add vArray(i)
        Else
            arrList.Add ""
        End If
    Next i

    '--output to sheet
    Sheets(1).Range("B2").Resize(arrList.Count) = _ 
    Application.Transpose(arrList.toarray())

End Sub

输出:

在此处输入图像描述

于 2013-01-11T09:59:53.687 回答