Match after specific value?

JPGKIll3R

New Member
Joined
Nov 2, 2016
Messages
10
Hello, mates!

I have a weird requirement in the job and haven't been able to figure it out by myself.
I;ve been given a weekly dataset (which needs to be in columns - per business requirements), similar to the table below:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Product[/TD]
[TD]W1[/TD]
[TD]W2[/TD]
[TD]W3[/TD]
[TD]W4[/TD]
[TD]...[/TD]
[TD]W52[/TD]
[/TR]
[TR]
[TD]Product 1[/TD]
[TD]Bad[/TD]
[TD]Bad[/TD]
[TD]Good[/TD]
[TD]Good[/TD]
[TD]...[/TD]
[TD]Good[/TD]
[/TR]
[TR]
[TD]Product 2[/TD]
[TD]Good[/TD]
[TD]Good[/TD]
[TD]Bad[/TD]
[TD]Good[/TD]
[TD]...[/TD]
[TD]Good[/TD]
[/TR]
</tbody>[/TABLE]

What I'm being prompted to do, is identify the Week on which the status passes from "Bad" to "Good".
On the Product 1 example, the formula is quite simple =MATCH("Good",Range,0)
However, the formula is pulling Week1 for the Product 2 example, where it should be Week 4, as that is the first time the product goes "Good" after being "Bad".

any help?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Here's a UDF that can be used just like a native Excel function after you install it. See the example below (copy the formula in G2 down).
Excel Workbook
ABCDEFG
1ProductW1W2W3W4Transition Week
2Product 1BadBadGoodGood3
3Product 2GoodGoodBadGood4
4Product 3GoodGoodGoodGoodNo Transition
Sheet2



Code:
Function TransitionWeek(R As Range) As Variant
Dim V As Variant, i As Long
V = R.Value
For i = 1 To UBound(V, 2)
    If i < UBound(V, 2) Then
        If V(1, i) = "Bad" And V(1, i + 1) = "Good" Then
            TransitionWeek = i + 1
            Exit Function
        End If
    Else
        TransitionWeek = "No Transition"
    End If
Next i
End Function
 
Upvote 0
Hi,

Formula option, change/adjust cell references/range as needed.

Let us know how you want to handle something like my sample Rows 4, 5, and 7:


Book1
ABCDEFG
1ProductW1W2W3W4
2Product 1BadBadGoodGoodW3
3Product 2GoodGoodBadGoodW4
4Product 3GoodGoodGoodGoodGood
5Product 4BadGoodGoodBadBad
6Product 5GoodBadBadGoodW4
7Product 7BadBadBadBadBad
Sheet569
Cell Formulas
RangeFormula
G2=IFERROR(IFNA(INDEX(A$1:E$1,,LOOKUP(2,1/SEARCH("Bad",B2:E2),COLUMN(B$1:E$1))+1),"Good"),"Bad")


Formula copied down.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,169
Members
453,021
Latest member
Justyna P

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