|
楼主 |
发表于 2024-6-19 15:29
|
显示全部楼层
Sub test3() 更新规避身份证号X大小写问题
Application.ScreenUpdating = False '关闭屏幕更新
Range("q7:q300000").Select
Selection.ClearContents
Columns("e:e").Select
Range("e7").Activate
Selection.Replace What:="x", Replacement:="X" '身份证字母小写改大写
Set d = CreateObject("Scripting.Dictionary")
With Sheets("Sheet1")
m = .[d65536].End(3).Row
ar = .Range("a7").Resize(m - 6, 18)
For i = 1 To UBound(ar)
If Len(ar(i, 4)) Then
gjz = ar(i, 4) & ar(i, 5) '关键字为姓名+身份证号
d(gjz) = i '记录行号
End If
Next
Dim files
Dim wb As Workbook
Dim sht As Worksheets
files = Application.GetOpenFilename(filefilter:="EXCEL 工作表(*.xlsx;*.xlsm;*.xls),*.xlsx;*.xlsm;*.xls", Title:="请选择要导入的工作簿", MultiSelect:=True) '选取,可以选多个excel文件
If Not IsArray(files) Then '如果按取消,没有选择的时候,退出程序
MsgBox "没有选定工作薄!~"
Exit Sub
End If
For i = UBound(files) To LBound(files) Step -1 '循环
Set wb = Workbooks.Open(files(i)) '依次打开
With wb.ActiveSheet
Columns("g:g").Select
Range("g7").Activate
Selection.Replace What:="x", Replacement:="X" '身份证字母小写改大写
m = .[f65536].End(3).Row
br = .Range("a7").Resize(m - 6, 21)
For j = 1 To UBound(br)
If Len(br(j, 6)) Then
gjz = br(j, 6) & br(j, 7)
If d.exists(gjz) Then
For k = 15 To 20
ar(d(gjz), 17) = ar(d(gjz), 17) + Val(br(j, k))
Next
End If
End If
Next
End With
wb.Close False
Next
.Range("a7").Resize(UBound(ar), UBound(ar, 2)) = ar
End With
Application.ScreenUpdating = True '打开屏幕更新
End Sub |
|