急急急!!!!EXCEL自定义函数无法调用 我在EXCEl里面自定义了一个函数,总是显示无效名称,紧急求助
由sheet1的选择,调用sheet2的设置,最后计算总分FunctionsumScoreA(startRowAsRange,endRowAsRange)sumScore...
由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 展开
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 展开
1个回答
展开全部
你这个不是 excel的自定义函数,是vba代码,要用vba调用才可以。
在界面上放一个按钮,在按钮的点击事件里调用
在界面上放一个按钮,在按钮的点击事件里调用
更多追问追答
追问
如何添加按钮事件啊,另外如何进行调用,这个vba方法,谢谢
追答
先加载控件工具箱,在菜单的空白位置,右键,控件工具箱打钩。
在控件工具箱你有个命令按钮,放到界面上,然后双击这个按钮,会自动打开vba界面。
你已经会写函数了,应该也会调用吧,
不过我还没有看你的函数是怎么功能,呵呵
Private Sub CommandButton1_Click()
Call sumScoreA(startRow, endRow) '应该要怎么处理,你看吧
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询