Select case with multiple case

Bandito1

Board Regular
Joined
Oct 18, 2018
Messages
233
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I got this worksheet that keeps track of returns.
Different items of a item can be returned (retour 1 and retour 2)

When an x is filled in behind the item in Retour (column B) the item should be colored red
When an x is filled in behind the in Returned (column C) the item should be colored black

This works.

But when 2 items are returned it doesn't work anymore.

When retour 2 is filled before retour 1 the item is black when i still miss the x in column C (returned)
Looks like the code is just going from top to bottom and doesn't look back

When retour 2 is complete it can happen that retour 1 isn't and then the item name should be still colored red.



VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Long

If Intersect(Target, Range("B:G")) Is Nothing Then Exit Sub
i = Target.Row
Select Case LCase(Range("B" & i).Value)
    Case "x"
        Range("A" & i).Font.color = RGB(255, 0, 0)
    Case ""
        Range("A" & i).Font.color = RGB(0, 0, 0)
    End Select
Select Case LCase(Range("C" & i).Value)
    Case "x"
        Range("A" & i).Font.color = RGB(0, 0, 0)
    End Select
Select Case LCase(Range("F" & i).Value)
    Case "x"
        Range("A" & i).Font.color = RGB(255, 0, 0)
    Case "F"
        Range("A" & i).Font.color = RGB(255, 0, 0)
    End Select
Select Case LCase(Range("G" & i).Value)
    Case "x"
        Range("A" & i).Font.color = RGB(0, 0, 0)
    End Select
End Sub

Book1
ABCDEFGHIJKLMN
1Retour 1Retour 2
2Item nameRetourReturnedRetourReturned
3Screwdriverxx
4Batchx
5Treexxxx
6GrassxxxThis one doesn't work. Retour 2 is complete but retour 1 not
Sheet1
 
Alternative solution with different approach.
Not really a solution if it doesn't do what the OP asked for is it? I just tried it out of curiosity and it doesn't work for a lot of combinations.
With what was asked for, these combinations of x's should show red but none of them do. There are other combinations that it does not work with, but I haven't included those as they should never appear in the proper table based on the information that has been provided.

Book1
ABCDEFG
1Retour 1Retour 2
2Item nameRetourReturnedRetourReturned
3Screwdriverxx
4Batchxx
5Treexxx
6Grassxxx
Sheet1
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,215,360
Messages
6,124,489
Members
449,166
Latest member
hokjock

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