|
本帖最后由 相对论R 于 2020-7-26 11:23 编辑
Sub 成绩()
Dim f As Range
MsgBox "请选择您要导入的平时成绩文件"
a = Application.GetOpenFilename("xls,*.xls,xlsx,*.xlsx", 2, , , True)
For i = LBound(a) To UBound(a)
Set p = GetObject("" & a(i))
Set q = p.ActiveSheet.UsedRange()
For j = 2 To q.Range("a65536").End(xlUp).Row
Set f = Sheet1.Range("C2:C40").Find(q.Range("a" & j).Value)
If f Is Nothing Then
Else: f.Offset(0, 2) = q.Range("d" & j)
End If
Next
Next
MsgBox "请选择您要导入的期末成绩文件"
b = Application.GetOpenFilename("xls,*.xls,xlsx,*.xlsx", 2, , , True)
x = Sheet1.UsedRange.Rows.Count
For k = LBound(b) To UBound(b)
Set r = GetObject("" & b(k))
Set s = p.ActiveSheet.UsedRange()
For m = 2 To s.Range("a65536").End(xlUp).Row
Set g = Sheet1.Range("C2:C40").Find(s.Range("a" & m).Value)
If g Is Nothing Then
Range("c" & x + 1) = s.Range("a" & m)
Range("d" & x + 1) = s.Range("b" & m)
Range("d" & x + 1) = 0
Range("f" & x + 1) = s.Range("d" & m)
x = x + 1
Else: g.Offset(0, 3) = s.Range("d" & m)
End If
Next
Next
For n = 2 To Sheet1.UsedRange.Rows.Count
If Range("e" & n) = "" Then
Range("e" & n) = 0
End If
If Range("f" & n) = "" Then
Range("f" & n) = 0
End If
Next
End Sub
先给你写一段代码,这段代码适用于平时成绩和期末成绩都只有一个的情形。 |
|