VBA 程序错误: 急!!下面的程序总报 type mismatch !的错误 是怎么回事啊????
Subtest()DimsumAsIntegersum=0DimrAsrangesum=checkdata(r)MsgBoxsumEndSubFunctioncheckd...
Sub test()
Dim sum As Integer
sum = 0
Dim r As range
sum = checkdata(r)
MsgBox sum
End Sub
Function checkdata(r) As Integer
Dim sum As Integer
For Each r In Selection
If r.Font.Color = vbRed Then
sum = sum + 1
End If
Next
checkdata = sum
End Function 展开
Dim sum As Integer
sum = 0
Dim r As range
sum = checkdata(r)
MsgBox sum
End Sub
Function checkdata(r) As Integer
Dim sum As Integer
For Each r In Selection
If r.Font.Color = vbRed Then
sum = sum + 1
End If
Next
checkdata = sum
End Function 展开
4个回答
展开全部
Sub test()
Dim sum As Integer
sum = 0
Dim r As Range
Set r = Selection '要付值给变量r
sum = checkdata(r)
MsgBox sum
End Sub
Function checkdata(ByVal r As Range) As Integer '定义参数引用类型
Dim r2 As Range '定义中间变量r2
Dim sum As Integer
For Each r2 In r '使用中间变量r2
If r2.Font.Color = vbRed Then '使用中间变量r2
sum = sum + 1
End If
Next
checkdata = sum
End Function
Dim sum As Integer
sum = 0
Dim r As Range
Set r = Selection '要付值给变量r
sum = checkdata(r)
MsgBox sum
End Sub
Function checkdata(ByVal r As Range) As Integer '定义参数引用类型
Dim r2 As Range '定义中间变量r2
Dim sum As Integer
For Each r2 In r '使用中间变量r2
If r2.Font.Color = vbRed Then '使用中间变量r2
sum = sum + 1
End If
Next
checkdata = sum
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不太清楚提问者的目的,如果是想求选取单元格中红色字体的个数的话,可以这样写。
Sub test()
Dim sum As Integer
sum = 0
Dim r As Range
Set r = Selection
sum = checkdata(r)
MsgBox sum
End Sub
Function checkdata(r) As Integer
Dim sum As Integer
Dim r1 As Range
For Each r1 In r
If r1.Font.Color = vbRed Then
sum = sum + 1
End If
Next
checkdata = sum
End Function
Sub test()
Dim sum As Integer
sum = 0
Dim r As Range
Set r = Selection
sum = checkdata(r)
MsgBox sum
End Sub
Function checkdata(r) As Integer
Dim sum As Integer
Dim r1 As Range
For Each r1 In r
If r1.Font.Color = vbRed Then
sum = sum + 1
End If
Next
checkdata = sum
End Function
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把 checkdata(r)里面的r去掉,注意两个地方都去掉。
追问
为甚么去掉就可以了呢?不是要把选中的单元格传给function函数吗?
追答
你自始自终都没有对r赋过值,函数里面是直接使用Selection获取选中内容
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-09-19
展开全部
,孔子
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询