VBA 判断单元格是否是错误值和0
答案:2 悬赏:70 手机版
解决时间 2021-02-23 01:44
- 提问者网友:川水往事
- 2021-02-22 19:20
我要用vba 判断 单元格a1到a85 和 B1 到B85 单元格的值是0还是错误值 如果是0和错误值 则提示单元格有错误
最佳答案
- 五星知识达人网友:思契十里
- 2021-02-22 20:46
1. Sub SelErr()
2. Dim Sel As Range, Rng As Range, ErrStr As String, ZoerStr As String
3. Set Rng = Range("A1:B85")
4. For Each Sel In Rng
5. If IsError(Sel) Then
6. ErrStr = ErrStr & Sel.Address(0, 0) & " "
7. ElseIf Sel <> "" And Sel = 0 Then
8. ZoerStr = ZoerStr & Sel.Address(0, 0) & " "
9. End If
10. Next Sel
11. MsgBox "A1:B85" & vbCr & "单元范围中存在错误值的单元格是:" & vbTab & ErrStr & vbCr & "存在 0值的单单元格是:" & vbTab & ZoerStr
12. End Sub
2. Dim Sel As Range, Rng As Range, ErrStr As String, ZoerStr As String
3. Set Rng = Range("A1:B85")
4. For Each Sel In Rng
5. If IsError(Sel) Then
6. ErrStr = ErrStr & Sel.Address(0, 0) & " "
7. ElseIf Sel <> "" And Sel = 0 Then
8. ZoerStr = ZoerStr & Sel.Address(0, 0) & " "
9. End If
10. Next Sel
11. MsgBox "A1:B85" & vbCr & "单元范围中存在错误值的单元格是:" & vbTab & ErrStr & vbCr & "存在 0值的单单元格是:" & vbTab & ZoerStr
12. End Sub
全部回答
- 1楼网友:一把行者刀
- 2021-02-22 21:22
1. sub selerr()
2. dim sel as range, rng as range, errstr as string, zoerstr as string
3. set rng = range("a1:b85")
4. for each sel in rng
5. if iserror(sel) then
6. errstr = errstr & sel.address(0, 0) & " "
7. elseif sel <> "" and sel = 0 then
8. zoerstr = zoerstr & sel.address(0, 0) & " "
9. end if
10. next sel
11. msgbox "a1:b85" & vbcr & "单元范围中存在错误值的单元格是:" & vbtab & errstr & vbcr & "存在 0值的单单元格是:" & vbtab & zoerstr
12. end sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯