Excel2000中用宏和VBa做成绩统计
分类: 计算机
时间: 2024-01-02 06:50:00
作者: 全国等级考试资料网
1. 设计流程,编制程序源代码:为便于说明做法,同时代码简短一点,这里以我校高三理科1-4班成绩统计为例,说明其做法。另外为使编写代码效率高一些,这里采用先录制一部分为宏,再在vba中打开相结合的办法编写。
① 从外部的“考试成绩.XLS”工作簿中将1-4班的成绩拷贝,依次粘贴到“成绩统计表.XLS”工作簿中的“理科”表中;
程序源代码:
Sub 拷外部理科0()
ActiveWindow.WindowState = xlMinimized
Windows("考试成绩.xls").Activate
ActiveWindow.WindowState = xlMaximized
Sheets("1班").Select
Range("A1:S60").Select
Selection.Copy
ActiveWindow.WindowState = xlMinimized
Windows("成绩统计表.xls").Activate
ActiveWindow.WindowState = xlMaximized
Sheets("理科").Select
ActiveWindow.ScrollRow = 1
Range("A1").Select
ActiveSheet.Paste
拷贝“考试成绩簿”中的1班成绩表中数据,粘贴到到成绩统计表工作簿的理科表A1
Range("S22").Select
ActiveWindow.LargeScroll Down:=1
Range("S44").Select
ActiveWindow.LargeScroll Down:=1
Range("S66").Select
Windows("考试成绩.xls").Activate
ActiveWindow.WindowState = xlNormal
Sheets("2班").Select
Range("A2").Select
ActiveWindow.SmallScroll Down:=43
Range("A2:S58").Select
Application.CutCopyMode = False
Selection.Copy
Windows("成绩统计表.xls").Activate
ActiveWindow.WindowState = xlNormal
Range("A61").Select
ActiveSheet.Paste
拷贝考试成绩簿中的2班成绩表中数据,粘贴到“成绩统计”工作簿的理科表A61
Windows("考试成绩.xls").Activate
ActiveWindow.WindowState = xlNormal
Sheets("3班").Select
Range("A1:S59").Select
Application.CutCopyMode = False
Selection.Copy
Windows("成绩统计表.xls").Activate
ActiveWindow.WindowState = xlNormal
Range("S58").Select
ActiveWindow.LargeScroll Down:=1
Range("S80").Select
ActiveWindow.LargeScroll Down:=1
Range("S102").Select
ActiveWindow.LargeScroll Down:=1
Range("A118").Select
ActiveSheet.Paste
拷贝成绩簿中的3班成绩表中数据,粘贴到成绩统计表工作簿的理科表A118
Rows("118:118").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
Range("D122").Select
Windows("考试成绩.xls").Activate
ActiveWindow.WindowState = xlNormal
Sheets("4班").Select
Range("A2:S71").Select
Selection.Copy
Windows("成绩统计表.xls").Activate
ActiveWindow.WindowState = xlNormal
ActiveWindow.LargeScroll Down:=1
Range("D144").Select
ActiveWindow.LargeScroll Down:=1
Range("D166").Select
ActiveWindow.LargeScroll Down:=1
Range("D188").Select
ActiveWindow.LargeScroll Down:=-1
Range("A176").Select
ActiveSheet.Paste‘拷贝四班成绩
End Sub
② 利用Excel的统计函数“RANK”将理科表中学生的各科成绩排名次;目的是让每位学生了解自己在全年级学生中的排名的位置。
程序代码
Sub 理名次()
Range("D2").Select
ActiveCell.FormulaR1C1 = "=RANK(RC[-1],R2C3:R246C3,0)"
Selection.AutoFill Destination:=Range("D2:D246"), Type:=xlFillDefault
Range("D2:D246").Select
ActiveWindow.LargeScroll Down:=-13
ActiveWindow.ScrollRow = 1 ’在工作表的D2单元格输入公式,并用拖的方式在D2-D246列复制
Selection.Copy
Range("F2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Replace What:="$c$2:$c$246", Replacement:="$e$2:$e$246", LookAt _
:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
拷贝D列粘贴到F列F2
Selection.Copy
Range("H2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Replace What:="e", Replacement:="g", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
拷贝D列粘贴到H列H2
Selection.Copy
Range("J2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
① 从外部的“考试成绩.XLS”工作簿中将1-4班的成绩拷贝,依次粘贴到“成绩统计表.XLS”工作簿中的“理科”表中;
程序源代码:
Sub 拷外部理科0()
ActiveWindow.WindowState = xlMinimized
Windows("考试成绩.xls").Activate
ActiveWindow.WindowState = xlMaximized
Sheets("1班").Select
Range("A1:S60").Select
Selection.Copy
ActiveWindow.WindowState = xlMinimized
Windows("成绩统计表.xls").Activate
ActiveWindow.WindowState = xlMaximized
Sheets("理科").Select
ActiveWindow.ScrollRow = 1
Range("A1").Select
ActiveSheet.Paste
拷贝“考试成绩簿”中的1班成绩表中数据,粘贴到到成绩统计表工作簿的理科表A1
Range("S22").Select
ActiveWindow.LargeScroll Down:=1
Range("S44").Select
ActiveWindow.LargeScroll Down:=1
Range("S66").Select
Windows("考试成绩.xls").Activate
ActiveWindow.WindowState = xlNormal
Sheets("2班").Select
Range("A2").Select
ActiveWindow.SmallScroll Down:=43
Range("A2:S58").Select
Application.CutCopyMode = False
Selection.Copy
Windows("成绩统计表.xls").Activate
ActiveWindow.WindowState = xlNormal
Range("A61").Select
ActiveSheet.Paste
拷贝考试成绩簿中的2班成绩表中数据,粘贴到“成绩统计”工作簿的理科表A61
Windows("考试成绩.xls").Activate
ActiveWindow.WindowState = xlNormal
Sheets("3班").Select
Range("A1:S59").Select
Application.CutCopyMode = False
Selection.Copy
Windows("成绩统计表.xls").Activate
ActiveWindow.WindowState = xlNormal
Range("S58").Select
ActiveWindow.LargeScroll Down:=1
Range("S80").Select
ActiveWindow.LargeScroll Down:=1
Range("S102").Select
ActiveWindow.LargeScroll Down:=1
Range("A118").Select
ActiveSheet.Paste
拷贝成绩簿中的3班成绩表中数据,粘贴到成绩统计表工作簿的理科表A118
Rows("118:118").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
Range("D122").Select
Windows("考试成绩.xls").Activate
ActiveWindow.WindowState = xlNormal
Sheets("4班").Select
Range("A2:S71").Select
Selection.Copy
Windows("成绩统计表.xls").Activate
ActiveWindow.WindowState = xlNormal
ActiveWindow.LargeScroll Down:=1
Range("D144").Select
ActiveWindow.LargeScroll Down:=1
Range("D166").Select
ActiveWindow.LargeScroll Down:=1
Range("D188").Select
ActiveWindow.LargeScroll Down:=-1
Range("A176").Select
ActiveSheet.Paste‘拷贝四班成绩
End Sub
② 利用Excel的统计函数“RANK”将理科表中学生的各科成绩排名次;目的是让每位学生了解自己在全年级学生中的排名的位置。
程序代码
Sub 理名次()
Range("D2").Select
ActiveCell.FormulaR1C1 = "=RANK(RC[-1],R2C3:R246C3,0)"
Selection.AutoFill Destination:=Range("D2:D246"), Type:=xlFillDefault
Range("D2:D246").Select
ActiveWindow.LargeScroll Down:=-13
ActiveWindow.ScrollRow = 1 ’在工作表的D2单元格输入公式,并用拖的方式在D2-D246列复制
Selection.Copy
Range("F2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Replace What:="$c$2:$c$246", Replacement:="$e$2:$e$246", LookAt _
:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
拷贝D列粘贴到F列F2
Selection.Copy
Range("H2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Replace What:="e", Replacement:="g", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
拷贝D列粘贴到H列H2
Selection.Copy
Range("J2").Select
ActiveSheet.Paste
Application.CutCopyMode = False