excel的(de)強大(dà)優(yōu)勢(shì)還在于它(tā)提供(gòng)的宏語言visual basic for application(vba).visual basic是windows環(huán)境下(xià)開(kāi)發(fā)應用(yòng)軟件的一種通(tōng)用程(chéng)序設計語(yǔ)言,功能強(qiáng)大,簡便易用。vba是它的(de)一個子集,可以廣泛地應用于(yú)microsoft公司(sī)開發的各種軟件中,例如(rú)word、excel、access等。
sub 分班()
const studentno = 191 '學生人數
const zdno = 12 '字(zì)段數(shù)
dim zd$(zdno) '定義爲12個字段(duàn)的數(shù)組
dim a(studentno, zdno), stu(60, zdno)
dim nam$(studentno), bjname$(60) '定義一(yī)個存放全(quán)校學(xué)生名(míng)字及(jí)各班學生(shēng)名字的數(shù)組
dim bj(studentno) '定義存(cún)放班(bān)級的(de)一個(gè)數組(zǔ)
'理科(kē)班工(gōng)作表
sheets("高三(sān)理").select
for i = 2 to studentno
bj(i) = activesheet.cells(i, 1)
nam$(i) = activesheet.cells(i, 2)
for j = 3 to zdno
a(i, j) = activesheet.cells(i, j)
next j
next i
'存放字(zì)段到數組中。
for i = 1 to zdno
zd$(i) = activesheet.cells(1, i)
next i
'先(xiān)建立各個班級(jí)的工作表
sheets("高三(sān)理").select
sheets("高(gāo)三理").copy after:=sheets("分數(shù)段")
sheets("高三理 (2)").select
sheets("高三理 (2)").name = "33"
for i = 2 to studentno
for j = 1 to zdno
activesheet.cells(i, j) = space$(1)
next j
next i
range("a1").select
for i = 1 to zdno
activesheet.cells(1, i) = zd$(i)
next i
'34到36班工作表(biǎo)的建立
for i = 34 to 36
x$ = mid$(str(33), 2)
sheets(x$).select
sheets(x$).copy after:=sheets("分數段(duàn)")
sheets(x$ + " (2)").select
sheets(x$ + " (2)").name = mid$(str(i), 2)
next i
'具體分班。
for k = 33 to 36
bjrs = 0
x$ = mid$(str(k), 2)
no = k mod 10
sheets(x$).select
for i = 2 to studentno
if bj(i) = no then
bjrs = bjrs + 1
bjname$(bjrs) = nam$(i)
for j = 3 to zdno
stu(bjrs, j) = a(i, j)
next j
end if
next i
for i = 2 to bjrs
activesheet.cells(i, 1) = no
activesheet.cells(i, 2) = bjname$(i)
for j = 3 to zdno
activesheet.cells(i, j) = stu(i, j)
next j
next i
next k
end sub
二.總(zǒng)分
const studentno = 190
const xknum = 6
const zdnum = 12
sheets("高三理").select
for i = 2 to studentno + 1
sum = 0
for j = 1 to xknum
sum = sum + activesheet.cells(i, j + 3)
next j
activesheet.cells(i, zdnum-1) = sum
next i
end sub
三.平均分(fèn)
sub 平均分()
const studentno = 190
const xknum = 6
dim fs(studentno, xknum), pjf3(4, 6), bjrs(4), qxpjf(6)
dim bj(studentno)
sheets("高(gāo)三理").select
'以下程序(xù)段用(yòng)于求全校(xiào)平均分
for i = 1 to studentno
bj(i) = activesheet.cells(i + 1, 1)
for j = 1 to xknum
fs(i, j) = activesheet.cells(i + 1, j + 3)
next j
next i
for i = 1 to xknum
sum = 0
for j = 1 to studentno
um = sum + fs(j, i)
next j
qxpjf(i) = sum / (j - 1)
next i
'以下程序段(duàn)用(yòng)于求各(gè)班平(píng)均分
for j = 1 to 4
for i = 1 to studentno
ifbj(i) = j + 2 then
bjrs(j) = bjrs(j) + 1
for k = 1 to xknum
pjf3(j, k) = pjf3(j, k) + fs(i, k)
next k
end if
next i
next j
for j = 1 to 4
for i = 1 to 6
pjf3(j, i) = pjf3(j, i) / bjrs(j)
next i
next j
'寫入(rù)各(gè)班各科平均(jun1)分
sheets("平(píng)均(jun1)分").select
for i = 1 to 4
for j = 1 to 6
activesheet.cells(i + 2, j + 1) = pjf3(i, j)
next j
next i
'寫(xiě)入(rù)全校(xiào)各科平均分
i = 7
for j = 1 to 6
activesheet.cells(i, j + 1) = qxpjf(j)
next j
end sub