20181013xlVba計算優秀率及合格率

2022-07-20 11:36:15 字數 2906 閱讀 8417

sub 計算高一優秀合格率()

dim wb as workbook

dim sht as worksheet

dim osht as worksheet

dim dos as object 'outstanding

const subjects = "語文數學英語物理化學生物政治歷史地理"

set dos = createobject("scripting.dictionary")

set sht = wb.worksheets("年級_本次成績總表")

with sht

endrow = .cells(.cells.rows.count, 1).end(xlup).row

endcol = .cells(1, .cells.columns.count).end(xltoleft).column

for j = 4 to endcol

if instr(subjects, .cells(1, j).text) > 0 then

subject = .cells(1, j).text

for i = 2 to endrow

if .cells(i, "y").value = "" then

goal = .cells(i, j).value

cls = .cells(i, 3).value

key = cls & ";" & subject

if goal <> "" then

if not dos.exists(key) then

if goal >= osline(subject, 1) then

os = 1

else

os = 0

end if

if goal >= osline(subject, 2) then

pass = 1

else

pass = 0

end if

dos(key) = array(1, os, pass)

else

ar = dos(key)

ar(0) = ar(0) + 1

if goal >= osline(subject, 1) then ar(1) = ar(1) + 1

if goal >= osline(subject, 2) then ar(2) = ar(2) + 1

dos(key) = ar

end if

end if

end if

next i

end if

next j

end with

'for each onekey in dos.keys

'ar = dos(onekey)

'debug.print onekey; " "; ar(0); " "; ar(1); " "; ar(2)

'next

set sht = wb.worksheets("年級_各科離均率")

with sht

startrow = 60

classcount = 20

subjectcount = 10

.cells(startrow + 1, 2).resize(classcount, subjectcount).clearcontents

for j = 2 to subjectcount + 1

subject = .cells(startrow, j).value

for i = startrow + 1 to startrow + 20

cls = .cells(i, 1).value

key = cls & ";" & subject

if dos.exists(key) then

ar = dos(key)

.cells(i, j).value = format(ar(1) / ar(0), "0.0%")

end if

next i

next j

startrow = 84

classcount = 20

subjectcount = 10

.cells(startrow + 1, 2).resize(classcount, subjectcount).clearcontents

for j = 2 to subjectcount + 1

subject = .cells(startrow, j).value

for i = startrow + 1 to startrow + 20

cls = .cells(i, 1).value

key = cls & ";" & subject

if dos.exists(key) then

ar = dos(key)

.cells(i, j).value = format(ar(2) / ar(0), "0.0%")

end if

next i

next j

end with

end sub

function osline(byval subject as string, byval level as long) as double 'level 1優秀0合格

select case subject

case "語文", "數學", "英語"

if level = 1 then

osline = 120

else

osline = 90

end if

case else

if level = 1 then

osline = 80

else

osline = 60

end if

end select

end function

20181013優秀的軟體推薦專欄(每日一次)

軟體介紹 小馬win7啟用工具一鍵解決win7 win8 win8.1 win10系統啟用問題,實現永久完美離線啟用,完全超越其他任何啟用工具。老品牌,夠放心,原創多種技術使oem7始終領先於其他啟用。軟體功能 1.精準識別電腦上安裝的所有office版本和windows系統 2.不需要輸入任何路徑...

x 的 x 次方等於10,求 x

當 x 的 x 次方為10時,求 x 的值,精確到小數字後9位 過程如下 2 的 2 次方 小於 10 3 的 3 次方 大於 10 因此 x 在 2 到 3 之間。找出整數部分後,需要計算出小數部分,然後把兩部分加到乙個串裡即可 可以以串的形式輸出,也可以轉成浮點數輸出,下面的程式是以串的形式輸出...

x 與 x的區別

簡單表示式如a 或 a,這兩種寫法代表同樣的意思,比如用在常見的for語句中 但當遞增increase或遞減decrease的運算結果被直接用在其它的表示式中時,它們就代表非常不同的意思了 a 中,變數a的值先增加,然後再計算整個表示式的值,因此增加後的值被用在了表示式的計算中 a 中,變數a的值在...