Public Sub GetCellPhone()
Dim CellPhone As String
Dim Arr As Variant
Dim Brr As Variant
Dim n As Long
Dim FolderPath As String
Dim FileName As String
Dim FilePath As String
Dim Zone As String
Dim WholeLine As String
Dim OneLine As String
Dim Phone As Variant
WholeLine = ""
FolderPath = ThisWorkbook.Path & "\"
FileName = "电话号码导出.txt"
FilePath = FolderPath & FileName
Debug.Print FilePath With Sheets("设置")
EndRow = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row
Set Rng = .Range("A2:A" & EndRow)
Brr = Rng.Value
End With With Sheets("原始数据")
EndRow = .Cells.Find("*", .Cells(1, 1), xlValues, xlWhole, xlByRows, xlPrevious).Row
For i = 2 To EndRow
For m = LBound(Brr) To UBound(Brr)
If InStr(1, .Cells(i, 1).Value, Brr(m, 1)) > 0 Then
Zone = .Cells(i, 1).Value
Arr = RegGetArray("(1\d{10})", .Cells(i, 2).Text)
CellPhone = Duplication(Arr)
If Len(CellPhone) > 1 Then
.Cells(i, 3).Value = "'" & CellPhone
Phone = Split(CellPhone, ";")
For n = LBound(Phone) To UBound(Phone)
OneLine = Phone(n) & vbCrLf
WholeLine = WholeLine & OneLine
Next n
End If
End If
Next m
Next i
End With
'Debug.Print WholeLine
Open FilePath For Output As #1
Print #1, WholeLine
Close #1
End Sub
Function Duplication(ByVal Arr As Variant) As String
Dim Dic As Object
Set Dic = CreateObject("Scripting.Dictionary")
For i = LBound(Arr) To UBound(Arr)
Key = CStr(Arr(i))
Dic(Key) = ""
Next i
If Dic.Count > 0 Then
Duplication = Join(Dic.keys, ";")
Else
Duplication = ""
End If
Set Dic = Nothing
End Function
Function RegGetArray(ByVal Pattern As String, ByVal OrgText As String) As String()
Dim Reg As Object, Mh As Object, OneMh As Object
Dim Arr() As String, Index As Long
Dim Elm As String
Set Reg = CreateObject("Vbscript.Regexp")
With Reg
.MultiLine = True
.Global = True
.Ignorecase = False
.Pattern = Pattern
If .test(OrgText) Then
Set Mh = .Execute(OrgText)
Index = 0
ReDim Arr(1 To 1)
For Each OneMh In Mh
Index = Index + 1
ReDim Preserve Arr(1 To Index)
Arr(Index) = OneMh.submatches(0)
Next OneMh
Else
ReDim Arr(1 To 1)
Arr(1) = ""
End If
End With
RegGetArray = Arr
Set Reg = Nothing
Set Mh = Nothing
End Function

  

20170822xlVBA ExportCellPhone的更多相关文章

随机推荐

  1. 【Python020--内嵌函数和闭包】

    一.内嵌函数&闭包 1.最好是访问全局变量而不是修改全局变量,修改全局变量Python会内部屏蔽(修改后,函数会内部创建一个和全局变量一抹一样的变量) >>> count = ...

  2. Delphi程序的主题(Theme)设置

    本文参考了 http://superlevin.ifengyuan.tw/delphi-change-vcl-style/ 在项目的工程文件中勾选主题,设置缺省主题为Windows 部分代码如下: u ...

  3. 01MySQL的 库、表初步认识

    一.安装&完全卸载 1.引导式安装 https://dev.mysql.com/downloads/installer/ 2.下载压缩包,解压后用控制台安装 初始化 mysqld --init ...

  4. CSS的初了解(更新中···)

    在前面,我们学习了html的结构.基本骨架.起名方式和选择器,接下来,我们就要学习CSS了. 首先,我们要知道CSS是什么. CSS 全称叫层叠样式表,作用是给html添加样式style,添加属性. ...

  5. Python3 tkinter基础 Canvas bind 鼠标左键点击时,在当前位置画椭圆形

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  6. Linux驱动开发调试 -- 打开dev_dbg()【转】

    本文转载自:https://blog.csdn.net/kunkliu/article/details/78048618 转载地址:http://blog.chinaunix.net/uid-2284 ...

  7. linux内核中的dquot是什么?

    答:这个与磁盘配额管理(disk quota)有关,内核配置选项为CONFIG_QUOTA,使能此选项意味着可以设置每个用户的硬盘使用限制.

  8. POJ - 1287 Networking 【最小生成树Kruskal】

    Networking Description You are assigned to design network connections between certain points in a wi ...

  9. bzoj 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 最小点覆盖

    链接 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 思路 这就是个上一篇的稍微麻烦版(是变脸版,其实没麻烦) 用边长为1的模板覆盖地图上的没有长草的土地,不能覆盖草地 ...

  10. Docker、Kubenets使用前配置

    1.开发人员需要确保机器上装有Docker并准确配置了Registry,能否推送相关镜像到Registry(运维人员无此要求) 2.能够访问Kubernetes APIServer相关API, 拥有相 ...