由sheet1的选择,调用sheet2的设置,最后计算总分
Function sumScoreA(startRow As Range, endRow As Range)
sumScoreA = 0
row1 = startRow.Value
row2 = endRow.Value
If row1 < row2 Then
For i = row1 To row2
tiMuNo = Trim(Sheet1.Cells(i, 1).Value)
answer = Trim(Sheet1.Cells(i, 2).Value)
tempScore = 0
myIndex = 0
For j = 2 To 11
oneType = Trim(Sheet2.Cells(j, 2).Value)
If tiMuNo = onType Then
myIndex = j
End If
Next
Select Case answer
Case Is = Trim(Sheet2.Cells(myIndex, 3).Value)
tempScore = Trim(Sheet2.Cells(myIndex, 4).Value)
Case Is = Trim(Sheet2.Cells(myIndex, 5).Value)
tempScore = Trim(Sheet2.Cells(myIndex, 6).Value)
Case Is = Trim(Sheet2.Cells(myIndex, 7).Value)
tempScore = Trim(Sheet2.Cells(myIndex, 8).Value)
End Select
sumScoreA = sumScoreA + tempScore
Next
End If
End Function
如何添加按钮事件啊,另外如何进行调用,这个vba方法,谢谢
追答先加载控件工具箱,在菜单的空白位置,右键,控件工具箱打钩。
在控件工具箱你有个命令按钮,放到界面上,然后双击这个按钮,会自动打开vba界面。
你已经会写函数了,应该也会调用吧,
不过我还没有看你的函数是怎么功能,呵呵
Private Sub CommandButton1_Click()
Call sumScoreA(startRow, endRow) '应该要怎么处理,你看吧
End Sub
函数调用真不会,原来只是用简单的求和,没用过这么复杂的
追答还是不要把,麻烦西
追问知道了,谢谢