电竞比分网-中国电竞赛事及体育赛事平台

分享

Excel宏操作繪制學(xué)生成績(jī)曲線圖

 零度寒冰 2010-11-17

需求:

原始數(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

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多