VBA 快速显示手机号是否正确

前台的小妹正在整理客户的相关信息,一个一个的输入客户的信息, 再一个一个的去校对。。怎么看的下去啊,so…

具体代码

Sub testPhone()
    Dim sh As Worksheet
    Set sh = Worksheets("sheet1")
    Dim row As Integer
    Dim phone As String
    Dim Column As Integer

    Set oRegExp = CreateObject("vbscript.regexp")
    With oRegExp
        .Global = True
        .IgnoreCase = True
        .Pattern = "(^[0-9]{3,4}\-[0-9]{7,8}$)|(^[0-9]{7,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}1[3-9][0-9]{9}$)"
    End With

    row = 1
    Column = 2 '手机号所在的列 A=1 这里要变的
    Do
    phone = sh.Cells(row, Column)

    If Not oRegExp.Test(phone) Then
        sh.Cells(row, Column).Font.Color = RGB(255, 0, 0)
    End If
    sh.Cells(row, Column) = "'" + phone
    row = row + 1
    Loop Until sh.Cells(row, Column) = ""
End Sub

跟小妹说,点一下,红色的就是电话号码输入有误的。

Written by 

你来或不来,我都在这里等你~

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注