20170822xlVBA ExportCellPhone
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的更多相关文章
随机推荐
- AppStore 添加回复
itunes connect 评论位置 1, 2, 添加用户权限:除了管理和客户支持可以回复.开发人员等只有只读权限
- centOS6.8开放防火墙端口
1.找到防火墙配置文件,/etc/sysconfig/iptables.如果是新装的linux系统,防火墙默认是被禁掉的,没有配置任何防火墙策略,所以不存在iptables.需要在控制台使用iptab ...
- Python3基础 list [] 创建空列表
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 response.read 输出网页的源代码
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- matlab练习程序(k-means聚类)
聚类算法,不是分类算法. 分类算法是给一个数据,然后判断这个数据属于已分好的类中的具体哪一类. 聚类算法是给一大堆原始数据,然后通过算法将其中具有相似特征的数据聚为一类. 这里的k-means聚类,是 ...
- HDU - 1875 畅通工程再续【最小生成树】
Problem Description 相信大家都听说一个"百岛湖"的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现.现在政府决定大力发展百岛湖 ...
- [SDOI2016]游戏 树剖+李超树
目录 链接 思路 update 代码 链接 https://www.luogu.org/problemnew/show/P4069 思路 树剖+超哥线段树 我已经自毙了,自闭了!!!! update ...
- P3178 [HAOI2015]树上操作
P3178 [HAOI2015]树上操作 思路 板子嘛,其实我感觉树剖没啥脑子 就是debug 代码 #include <bits/stdc++.h> #define int long l ...
- html 之 浮动(待补充)
通过设置float 样式属性来决定区块标签的浮动 问题:区块与非区块浮动的特点(左右) 区块与区块浮动的特点(左右) ie浏览器与谷歌等浏览器的效果差异
- oracle单行函数 之 时间函数
select systemdate from dual --得到时间 select systemdate+300 from dual --日期 +数字=日期,表示若干天之后的日期 select s ...