1、新建一个Excel表格,最好是xls格式的。
2、将阅卡机数据复制粘贴到到Sheet1中。
3、按Alt+F11打开VBA窗口。新建一个模块,粘贴如下代码:
Sub test()
Dim rg, n, str
Dim re As Object
n = Range("a65535").End(xlUp).Row
'Debug.Print n
rg = Range("A1:A" & n)
str = ""
For i = 1 To UBound(rg)
'Debug.Print rg(i, 1)
str = str + rg(i, 1)
Next
'Debug.Print str
Set re = CreateObject("vbscript.regexp")
With re
.Global = True
.IgnoreCase = True
.Pattern = "(19[\d][\d][\d]) ([\d]+)\.[\d]"
End With
Range("P2:Q" & n).ClearContents '这里清除数据,更改一
Set mat = re.Execute(str)
Application.ScreenUpdating = False
For n = 1 To mat.Count
Debug.Print mat(n - 1)
Range("P" & (n + 1)) = Trim(Left(mat(n - 1), 5)) '取出学号,更改二
Range("Q" & (n + 1)) = Trim(Mid(mat(n - 1), 6, Len(mat(n - 1)))) '取出分数,更改三
Next
Application.ScreenUpdating = True
End Sub
4、在Sheet1中插入一个按钮,指定宏为test,点击按钮自动生成结果。
5、可以在此表中提前列出学生学号及名字,利用公式查出对应学生成绩。