Select Case Loop with multiple criteria

bwm21

New Member
Joined
Oct 7, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I am building a macro to evaluate multiple (only 3 for now) conditions through a range of data. Here is what I have so far:

VBA Code:
Sub Trial2()

Dim myCell As Range

For Each myCell In Range("Q2:S500")
    With myCell.Offset(0, -15)
        Select Case myCell.Value
            Case Is = "Production", "In-Scope", "Deployed"
                .Value = "Qualified"
            Case Else
                .Value = "Not Qualified"
        End Select
    End With
Next myCell

End Sub

My question is how do I create a Case to evaluate these criteria individually.
Example: The object being evaluated is "Production", "In-Scope", but is anything other than "Deployed"
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Not sure about your needs but

VBA Code:
Sub Trial2()

Dim myCell As Range

For Each myCell In Range("Q2:S500")
    With myCell.Offset(0, -15)
        Select Case myCell.Value
          Case "Production", "In-Scope": .Value = "Qualified"
          Case "Deployed": .Value = "Qualified"
          Case Else: .Value = "Not Qualified"
        End Select
    End With
Next myCell
End Sub
 
Upvote 0
I see what you are thinking. Let me try to phrase my need better:

Columns Q-R will be evaluated in each row. The goal will be to evaluate based on different combinations of those 3 criteria for the resulting .Value statement. If all 3 of those criteria are met, then it will be qualified.

If for Example Q is "Production", R is "In-Scope", but S is anything other than "Deployed", the .Value will be "Not Deployed".
However
If R is "In-Scope", S is "Deployed", but Q is anything other than "Production", the .Value will be "Non-Production".
 
Upvote 0
Are you ok with a formula?

Excel Formula:
=CHOOSE(MAX(IF(ISERROR(MATCH({"Production","In-Scope,"Deployed"},Q2:S2,0)),{2,3,4},1)),"Qualified","Non-Production","Not-In-Scope","Not-Deployed")
 
Upvote 0
I see what you are thinking. Let me try to phrase my need better:

Columns Q-R will be evaluated in each row. The goal will be to evaluate based on different combinations of those 3 criteria for the resulting .Value statement. If all 3 of those criteria are met, then it will be qualified.

If for Example Q is "Production", R is "In-Scope", but S is anything other than "Deployed", the .Value will be "Not Deployed".
However
If R is "In-Scope", S is "Deployed", but Q is anything other than "Production", the .Value will be "Non-Production".
I would probably use IF THEN formulas where you can also make use of AND instead of SELECT CASE in this situation.
 
Upvote 0
Formula converted to VBA

VBA Code:
Sub jec()
 For Each myCell In Range("Q2:Q500")
   With myCell
    .Offset(0, -15) = Evaluate(Replace("choose(max(if(iserror(match({""Production"",""In-Scope"",""Deployed""},$$,0)),{2,3,4},1)),""Qualified"",""Non-Production"",""Not-In-Scope"",""Not-Deployed"")", "$$", .Resize(, 3).Address))
   End With
 Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,194
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top