|
需求:
原始數(shù)據(jù)是多張表, 每張表中的內(nèi)容為同一班級(jí)一次考試的各科成績(jī), 多張表意味著多次考試。 通過(guò)宏命令在菜單中建立一個(gè)命令按鈕, 能夠生成一個(gè)學(xué)生多次考試的單科/平均分等成績(jī)曲線圖。
Demo:

沒(méi)有網(wǎng)絡(luò)可以查資料,所以搞了好幾天晚上
今天終于弄完(還有好多情況沒(méi)有考慮)
通過(guò)生成一個(gè)匯總頁(yè)面方式做的圖
(正常應(yīng)該是引用多sheet頁(yè)的單元格,不清楚是不是這樣)
結(jié)果:

基本功能:根據(jù)選定單元格所在行,生成成績(jī)曲線圖
宏代碼,版本Office 2007
Sub 成績(jī)曲線圖() ' ' 成績(jī)曲線圖 Macro ' 'studentCode存放學(xué)號(hào) Dim studentCode As String studentCode = Selection.Value 'MsgBox (studentCode) '單元格所在行 Dim cellRow, cellColumn As Integer cellRow = ActiveCell.Row '活動(dòng)單元格所在的行數(shù) cellColumn = ActiveCell.Column '活動(dòng)單元格所在的列數(shù) 'MsgBox (cellRow) 'MsgBox (cellColumn)
'刪除存在的個(gè)人匯總頁(yè) Dim sheetsCount As Integer For sheetsCount = 1 To Sheets.Count If Sheets(sheetsCount).Name = "個(gè)人成績(jī)匯總" Then '取消顯示提示框 Application.DisplayAlerts = False Sheets("個(gè)人成績(jī)匯總").Select ActiveWindow.SelectedSheets.Delete '還原顯示提示框 Application.DisplayAlerts = True Exit For Else End If Next sheetsCount
'新建個(gè)人成績(jī)匯總頁(yè) Sheets.Add After:=Sheets(Sheets.Count) Sheets(Sheets.Count).Name = "個(gè)人成績(jī)匯總" '構(gòu)建行頭 Sheets(1).Select Rows("1:1").Select Selection.Copy Sheets("個(gè)人成績(jī)匯總").Select Rows("1:1").Select ActiveSheet.Paste '復(fù)制成績(jī) Dim term As Integer For term = 1 To Sheets.Count - 1 Sheets(term).Select Rows(cellRow).Select Selection.Copy Sheets("個(gè)人成績(jī)匯總").Select Rows(term + 1).Select ActiveSheet.Paste Next term '處理列頭 For sheetsCount = 1 To Sheets.Count - 1 Cells(sheetsCount + 1, "A").Value = Sheets(sheetsCount).Name Next sheetsCount '設(shè)置A1單元格為學(xué)生名,并刪除姓名列 Range("A1").Value = Range("B2").Value Columns(2).Delete '計(jì)算每行各科考試平均分 Dim rowCount, colCount As Integer rowCount = ActiveSheet.Range("A65535").End(xlUp).Row colCount = ActiveSheet.Range("IV1").End(xlToLeft).Column 'MsgBox (rowCount) 'MsgBox (colCount) '寫平均分四個(gè)字 Cells(1, colCount + 1).Value = "平均分" '逐行計(jì)算平均分 Dim i, j As Integer Dim sum As Integer For i = 2 To rowCount For j = 2 To colCount sum = sum + Cells(i, j).Value Next j Cells(i, colCount + 1).Value = sum / (colCount - 1) sum = 0 Next i '選擇區(qū)域 'Range(Cells(1, 1), Cells(rowCount, colCount + 1)).Select '制圖 ActiveSheet.Shapes.AddChart.Select ActiveChart.SetSourceData Source:=Range(Cells(1, 1), Cells(rowCount, colCount + 1)) ActiveChart.ChartType = xlLineMarkers ActiveChart.PlotBy = xlColumns ' End Sub
|