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
VBA 程序错误: 急!!下面的程序总报 type mismatch !的错误 是怎么回事啊????
答案:4 悬赏:30 手机版
解决时间 2021-02-12 21:33
- 提问者网友:沉默的哀伤
- 2021-02-12 01:03
最佳答案
- 五星知识达人网友:duile
- 2021-02-12 01:28
不太清楚提问者的目的,如果是想求选取单元格中红色字体的个数的话,可以这样写。
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
全部回答
- 1楼网友:拜訪者
- 2021-02-12 03:25
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
- 2楼网友:杯酒困英雄
- 2021-02-12 02:34
,孔子
- 3楼网友:西风乍起
- 2021-02-12 02:14
把 checkdata(r)里面的r去掉,注意两个地方都去掉。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯