在Select Case中使用InStr函数 [英] Using a InStr function within a Select Case

查看:147
本文介绍了在Select Case中使用InStr函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎不起作用.有什么办法可以做我想在这里做的事吗?如果值在给定的字符串中,则无法选择情况:

This does not seem to be working. Is there a way to do what I am trying to do here? I cant a case to be selected if the value is in a given sting:

Select Case gTTD.Cells(r, 4)

     Case InStr(gTTD.Cells(r, 4), "MASTER LOG")
         resp = "MM LOG"
      Case InStr(gTTD.Cells(r, 4), "MASTER MET")
         resp = "MM MET"
     Case "PIR"
         gTTD.Cells(r, 7) = "Martin Trépanier"
         resp = "Martin Trépanier"

 End Select

我了解为什么这行不通,但是有办法使它行得通吗?谢谢

I understand why this cant work but is there a way of making it work? thank you

谢谢

推荐答案

这是我使用的一个小技巧,select语句只是想查找相同的结果.这是一个简单的示例:

Here is a little trick I use, the select statement just wants to find results that are the same. Here is a simple example:

    Select Case True
        Case (1 = 2)
            Stop
        Case (2 = 3)
            Stop
        Case (4 = 4)
            Stop
        Case Else
            Stop
    End Select

这将属于4 = 4的情况.在您的示例中,这可能是简单的答案:

This will fall into the 4=4 case. In your example, this might be the simple answer:

Select Case True

     Case (InStr(gTTD.Cells(r, 4), "MASTER LOG") > 0)
         resp = "MM LOG"
      Case (InStr(gTTD.Cells(r, 4), "MASTER MET") > 0)
         resp = "MM MET"
     Case else
         gTTD.Cells(r, 7) = "Martin Trépanier"
         resp = "Martin Trépanier"
 End Select

这篇关于在Select Case中使用InStr函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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