Excel VBA Case不起作用 [英] Excel VBA Case doesn't work

查看:82
本文介绍了Excel VBA Case不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Public Function Test(y As Double)
Select Case y  
Case y = 0           //problem starts here
Test= "No value"     // problem ends here

Case Else
s = 0
For i = 1 To 3
s = s + 20 / y
Next
Test= s
End Select
End Function

当y = 0时,我得到的结果是"#Value!".这里有什么问题.当y不为0时,一切正常.

When the y=0 the result I get is "#Value!" what is the problem here. When y is not 0 everything works.

推荐答案

您使用的大小写不正确,您不应只说 case 0 就说 y = 0 case"0"

You are using case incorrectly, you are not supposed to say y=0 just say case 0 or case "0"

其他部分起作用,因为每个包含0的值都处于相同的情况.

Else part works because every value including 0 goes to the same case.

Public Function Test(y As Double)
  Select Case y  
    Case  "0"         // This is the correct way to use it     
      Test= "No value"     

    Case Else
      s = 0
      For i = 1 To 3
        s = s + 20 / y
      Next
      Test= s
  End Select
End Function

这篇关于Excel VBA Case不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆