Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a InStr function within a Select Case

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

Thank you

like image 340
user2385809 Avatar asked Feb 19 '14 17:02

user2385809


1 Answers

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
like image 146
Steve Avatar answered Nov 11 '22 20:11

Steve