1、如下图A列含有部分身份证号码,现在我们想要提取出这些身份证号码的年龄,首先我们选中这些身份证号码。
2、同时按下ATL+F11
3、点击sheet1,然后在代码区输入代码
4、按下F5,然后点击运行
5、点击B2单元格作为存放单元格,然后点击【确定】即可完成
6、完成效果如下图,最后跟大家分享一下这里使用的vba代码,如果有需要大家可以复制使用,另外如需要代做vba,可以百度方方格子。Sub ?????患修校楷????????() On Error Resume Next Dim ar, i, ii Dim tmp If Selection.Areas.Count > 1 Then Exit Sub If Selection.Cells.Count > Columns.Count Then MsgBox "?????????????" Exit Sub End If ar = Selection Set rngs = Application.InputBox("???????????????", "???", , , , , , 8) '???????? If Selection.Cells.Count = 1 Then tmp = IDAge(ar) ar = tmp rngs.Cells(1, 1) = ar Exit Sub End If '???????? Randomize Timer For i = 1 To UBound(ar) For ii = 1 To UBound(ar, 2) tmp = IDAge(ar(i, ii)) ar(i, ii) = tmp Next Next rngs.Resize(UBound(ar), UBound(ar, 2)) = arEnd SubFunction IDAge(sid) As String Dim rlt As Date Select Case Len(sid) Case 15 rlt = Format("19" & Mid(sid, 7, 6), "0000-00-00") Case 18 rlt = Format(Mid(sid, 7, 8), "0000-00-00") Case 0 IDAge = "" Exit Function Case Else IDAge = "??Ч" Exit Function End Select IDAge = Year(Date) - Year(rlt)End Function