Using a InStr function within a Select Case

梦想与她 提交于 2019-12-01 04:13:43

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

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
Pedrumj

try this

dim r as integer
for r = 1 to 'number of rows
    if Instr(gTTD.Cells(r, 4), "MASTER LOG") <> 0 then
         resp = "MM LOG"
    elseif Instr(gTTD.Cells(r, 4), "MASTER MET") <> 0 then
        resp = "MM MET"
    else
        gTTD.Cells(r, 7) = "Martin Trépanier"
        resp = "Martin Trépanier"
    end if
next r
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!