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. Eclipse中在xml文件中,ctrl+左键的快捷键,点击class定位,不生效

    修改方式:   第一种方式:Window -> Preferences -> General -> Editors -> File Associations           ...

  2. javascript对文件的读写

    整合了一下网上对于js实现文件读写的代码,但是该功能只能在ie浏览器下执行,另外有些电脑上的ie需要设置. 下面是写入代码: var fso = new ActiveXObject("Scr ...

  3. 内置函数之sorted,filter,map

    # 4,用map来处理字符串列表,把列表中所有人都变成sb,比方alex_sb # name=['oldboy','alex','wusir'] # print(list(map(lambda i:i ...

  4. CodeChef - ELHIDARR Find an element in hidden array(互动题)题解

    题意:有一串不递减的串,串中的任意元素都有k个,除了一个元素,他只有1 <= n < k-1个,你现在能向oj做出以下操作: 输出:1 pos,oj会返回pos位置的元素值 输出:2 va ...

  5. 通过cmd调用Powershell脚本

    一共需要3个文件,把这3个文件放在一个路径下 UTF8NoBOM.bat   这个文件是为了调用ps1 pwsh -file "%cd%\UTF8NoBOM.ps1" UTF8No ...

  6. js动画(速度)

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta ht ...

  7. git删除远程分支文件,不改变本地文件

    git提交项目时候踩的Git的坑 特别 由于准备春招,所以希望各位看客方便的话,能去github上面帮我Star一下项目 https://github.com/Draymonders/Campus-S ...

  8. 题解——UVA11997 K Smallest Sums

    题面 背景 输入 输出 翻译(渣自翻) 给定K个包含K个数字的表,要求将其能产生的\( k^{k} \)个值中最小的K个输出出来 题解 k路归并问题的经典问题 可以转化为二路归并问题求解 考虑A[], ...

  9. Unity3D学习笔记(二十七):MVC框架下的背包系统(2)

    Tools FileTools using System.Collections; using System.Collections.Generic; using UnityEngine; using ...

  10. spring读取bean有几种方式

    bean加载到spring的方式: 第一种:xml 第二种:注释「一定要配合包扫描」: <context:component-scan base-package="Cristin.Co ...