Find specific text in 1 column and look for subsequent specific text in another column and format

Smiley54665

New Member
Joined
Feb 25, 2014
Messages
3
Hi,

I have a spreadsheet in excel 2010 that stores a list of results from a piece of equipment. If someone could give me a clue where to even start with this, I might be able to get somewhere, but I am lost. I need VBA code that will accomplish the following:

  • Find any instance of “Failed” in column K
  • Look for the next time that location (identified in column B) is tested again on the same date
  • If that next test on the same date results in “Passed” in column K, I need the cells in A:L of the row of the “Passed” test and the initial “failed” result to have a green background color (see sample).
  • This would need to work if there were multiple retests to accomplish the “Passed” result in column K (see second set of green lines on sample).


  • Lastly, if there was a “failed” result in column K, but there was no follow up test on the same date that resulted in a “passed” result, I need the cells in A:L of that row to run orange.

I don’t know if this makes any sense or is even possible, but any help would be greatly appreciated. Thank you!

Here is some sample data. I couldn't figure out how to highlight the text in the sample, so I changed the color of the text instead:
PLANNAMELOCATIONSURFACECHANNELCOUNTSPF-LIMITTESTNUMDATETIMEOPERATORSTATUSSERIAL #
PLAN 1FSURFACE 1LUM5050110/18/1420:07:26OPERATOR 2FailedNL-3740
PLAN 1ESURFACE 1LUM5050110/18/1420:07:26OPERATOR 2FailedNL-3740
PLAN 1ESURFACE 1LUM00110/18/1420:09:25OPERATOR 2PassedNL-3740
PLAN 1BSURFACE 1LUM00110/17/1422:09:31OPERATOR 2PassedNL-3740
PLAN 1CSURFACE 1LUM00110/17/1422:10:21OPERATOR 2PassedNL-3740
PLAN 1DSURFACE 1LUM15910110/17/1422:11:53OPERATOR 2FailedNL-3740
PLAN 1DSURFACE 1LUM3230110/17/1422:15:08OPERATOR 2FailedNL-3740
PLAN 1DSURFACE 1LUM00110/17/1422:17:01OPERATOR 2PassedNL-3740

<tbody>
</tbody><colgroup><col><col><col><col><col><col><col><col><col><col><col><col></colgroup>
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG31Oct58
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Q [COLOR="Navy"]As[/COLOR] Variant, K [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("B2"), Range("B" & Rows.Count).End(xlUp))
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
  [COLOR="Navy"]If[/COLOR] Not .Exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
        .Add Dn.Value, Array(Dn, Dn.Offset(, 9).Value)
    [COLOR="Navy"]Else[/COLOR]
        Q = .Item(Dn.Value)
            [COLOR="Navy"]Set[/COLOR] Q(0) = Union(Q(0), Dn)
            Q(1) = Dn.Offset(, 9).Value
        .Item(Dn.Value) = Q
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]


 [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] K [COLOR="Navy"]In[/COLOR] .keys
 [COLOR="Navy"]If[/COLOR] .Item(K)(1) = "Failed" [COLOR="Navy"]Then[/COLOR]
    .Item(K)(0).Offset(, -1).Resize(, 12).Font.ColorIndex = 46
 [COLOR="Navy"]ElseIf[/COLOR] .Item(K)(1) = "Passed" [COLOR="Navy"]Then[/COLOR]
    .Item(K)(0).Offset(, -1).Resize(, 12).Font.ColorIndex = 10
 [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] K
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,214,786
Messages
6,121,553
Members
449,038
Latest member
Guest1337

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