|
楼主 |
发表于 2014-8-11 11:40
|
显示全部楼层
gun0080 发表于 2014-8-11 00:11
想把这个功能加到我做的系统里,你能公开代码吗?
Sub 从身份证号码中提取信息()
m = Cells(1, 10).Value
If m > 1 Then
Range("B2").Select
ActiveCell.FormulaR1C1 = "=LEN(RC[-1])"
Range("C2").Select
Selection.FormulaArray = _
"=OR(LEN(RC[-2])=15,IF(LEN(RC[-2])=18,MID(""10X98765432"",MOD(SUM(MID(RC[-2],ROW(INDIRECT(""1:17"")),1)*2^(18-ROW(INDIRECT(""1:17"")))),11)+1,1)=RIGHT(RC[-2])))"
Range("D2").Select
Selection.FormulaArray = _
"=IF(LEN(RC[-3])=15,REPLACE(RC[-3],7,,19)&MID(""10X98765432"",MOD(SUM(MID(REPLACE(RC[-3],7,,19),ROW(INDIRECT(""1:17"")),1)*2^(18-ROW(INDIRECT(""1:17"")))),11)+1,1),RC[-3])"
Range("E2").Select
ActiveCell.FormulaR1C1 = "=IF(MOD(RIGHT(LEFT(RC[-4],17)),2),""男"",""女"")"
Range("F2").Select
ActiveCell.FormulaR1C1 = _
"=DATE(MID(RC[-5],7,IF(LEN(RC[-5])=18,4,2)),MID(RC[-5],IF(LEN(RC[-5])=18,11,9),2),MID(RC[-5],IF(LEN(RC[-5])=18,13,11),2))"
Range("G2").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-6]<>"""",DATEDIF(TEXT((LEN(RC[-6])=15)*19&MID(RC[-6],7,6+(LEN(RC[-6])=18)*2),""#-00-00""),TODAY(),""y""),)"
Range("H2").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-7]<>"""",VLOOKUP(LEFT(RC[-7],2),地址码!C[-7]:C[-6],2,),)"
Range("I2").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-8]<>"""",VLOOKUP(LEFT(RC[-8],6),地址码!C[-8]:C[-7],2,),)"
If m > 2 Then
Range("B2:I2").Select
Selection.AutoFill Destination:=Range(Cells(2, 2), Cells(m, 9)), Type:=xlFillDefault
End If
Range(Cells(2, 2), Cells(m, 9)).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Else
MsgBox "请在A列输入您要查找的身份证号码。", vbOKOnly, "相知_相遇 QQ:280027432"
Cells(2, 1).Select
End If
End Sub
Sub 清空()
If MsgBox("您确定要清空吗?", vbQuestion + vbYesNo, "相知_相遇 QQ:280027432") = vbYes Then
Columns("A:I").Select
Selection.ClearContents
Range("A1").Select
ActiveCell.FormulaR1C1 = "身份证号码"
Range("B1").Select
ActiveCell.FormulaR1C1 = "位数"
Range("C1").Select
ActiveCell.FormulaR1C1 = "是否正确"
Range("D1").Select
ActiveCell.FormulaR1C1 = "18位身份证号"
Range("E1").Select
ActiveCell.FormulaR1C1 = "性别"
Range("F1").Select
ActiveCell.FormulaR1C1 = "出生日期"
Range("G1").Select
ActiveCell.FormulaR1C1 = "年龄"
Range("H1").Select
ActiveCell.FormulaR1C1 = "所属省份"
Range("I1").Select
ActiveCell.FormulaR1C1 = "所属地区"
End If
Range("A2").Select
End Sub |
|