VBA判断多表多个单元格字符(如身份证号,手机号)长度是否符合要求并报告结果
发布网友
发布时间:2022-04-22 23:05
我来回答
共1个回答
热心网友
时间:2023-10-08 16:08
一个一个来,这个是判断身份证的,判断手机号的,等会发给你
Sub fdfd()
n = Application.InputBox("请输入身份证号码:")
If n = False Then
Exit Sub
ElseIf n = "" Then
MsgBox "不能输入空值"
Else
wi = Array("7", "9", "10", "5", "8", "4", "2", "1", "6", "3", "7", "9", "10", "5", "8", "4", "2")
y = Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2")
For h = 0 To 16
r = Mid(n, h + 1, 1)
If IsNumeric(r) = False Then
MsgBox "第 " & h + 1 & " 位为非法字符"
Exit Sub
End If
s = s + r * wi(h)
Next h
t = s Mod 11
If UCase(Mid(n, 18)) = y(t) Then
MsgBox "身份证号码正确"
Else
MsgBox "身份证号码不正确"
End If
End If
End Sub
这个是判断手机号的
Sub test()
Dim n, i%, str
n = Application.InputBox("请输入手机号", , , , , , , Type:=1)
If Len(n) <> 11 Then
MsgBox "你输入的数字不是手机号!"
Exit Sub
Else
MsgBox pd(CInt(Left(n, 3)))
End If
End Sub
Function pd(ByVal str As Integer)
Select Case str
Case 130, 131, 132, 155, 156, 185, 186
pd = "手机号归属中国联通"
Case 134, 135, 136, 137, 138, 139, 147, 150, 151, 152, 154, 157, 158, 159, 182, 183, 187, 188
pd = "手机号归属中国移动"
Case 133, 153, 180, 11, 1
pd = "手机号归属中国电信"
Case Else
pd = "非法号码或者暂时不确定运营商!"
End Select
End Function