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. Click()与Submit()

    <input type="button" /> 定义可点击的按钮,但没有任何行为.如果你不写javascript 的话,按下去什么也不会发生. button 类型常用于 ...

  2. checkbox勾选事件,JQ设置css,下拉框JQ选中

    <input id="CheckMainCompany" type="checkbox"/> $(function() { $("#Che ...

  3. Array数组集合的排序

    /* ######### ############ ############# ## ########### ### ###### ##### ### ####### #### ### ####### ...

  4. Restful framework【第五篇】解析器

    基本使用 -解析器 -源码从request.data -全局配置 -'DEFAULT_PARSER_CLASSES':['rest_framework.parsers.JSONParser'], -局 ...

  5. for和while循环的区别

    区别:for循环,就是遍历某一对象,通俗说就是根据循环次数限制做多少次重复操作.while循环,是当满足什么条件的时候,才做某种操作. for为遍历循环 while为直到循环

  6. Elasticsearch-->Get Started-->Modifying Your Data

    https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-modify-data.html Mod ...

  7. 网络_TCP连接的建立与释放

    三报文握手 1.概述 TCP是面向连接的协议.TCP建立连接的过程叫做握手,握手需要在客户和服务器之间交换三个TCP报文段,即我们说的"三次握手"(严格讲是一次握手过程中交换了三个 ...

  8. Kubernetes之总体了解

    Kubernetes:架构.基本概念.用于总体了解 Kubernetes系列之介绍篇:优势.用途 Kubernetes核心概念总结

  9. Git 提交的正确姿势:Commit message 编写指南

    http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html Git 每次提交代码,都要写 Commit message( ...

  10. 批量Excel数据导入Oracle数据库

    由于一直基于Oracle数据库上做开发,因此常常会需要把大量的Excel数据导入到Oracle数据库中,其实如果从事SqlServer数据库的开发,那么思路也是一样的,本文主要介绍如何导入Excel数 ...