1

I have two columns lets say A and B. In column A I've values like Apple, banana, Brinjal and in column B Ripe and Not Ripe. In column C I want to check if it is a fruit or vegetable and then riped or not riped. I want the below result.

How to use multiple Case statements?

Please see the below table

Private Sub CommandButton1_Click()
     Dim category As String, result As String
     For i = 2 To 1000
         category = Range("A" & i).Value
         Select Case category
             Case "Apple"
                   result = "Fruit"
             Case "Brinjal"
                   result = "Vegetable"
         End Select
         Range("C" & i).Value = result
     Next
End Sub

2 Answers 2

2

you can specify the list of values using comma:

Private Sub CommandButton1_Click()
    Dim category As String, result As String
    For i = 2 To 1000
        category = Range("A" & i).Value
        Select Case category
            Case "Apple", "Banana", "Orange"
                result = "Fruit"
            Case "Brinjal"
                result = "Vegetable"
            Case else
                result = vbnullstring
            End Select
        Range("C" & i).Value = Range("B" & i).Value & " " & result
    Next i
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, Thanks for your input
1

If i well understand...

For i = 1 To 4
    category = Range("A" & i).Value
    Select Case category
        Case "Apple", "Orange", "Banana"
            result = "Fruit"
        Case "Brinjal","xxx"
            result = "Vegetable"
        Case Else
            result = ""
    End Select

    'If th onlys status possibles are ripe and not riped

    Range("C" & i).Value = Range("B" & i).Value & " " & result
Next

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.