Solved

Excel vba: Match the contents of three cells - then do find & replace

Posted on 2011-03-17
3
458 Views
Last Modified: 2013-11-25
Hi! I have a workbook that includes two worksheets: "Open" and "COA TRACE". This is what I need to have happen:

1. "Open" has a beginning and ending range of numbers in columns M & N. In column J, there are event codes we are looking for.

2. "COA TRACE" shows all of the events (Col. G) that have happened for the number ranges(Cols. A & B).

3. I need a macro that will match up the number ranges and then look to see if col G in "COA TRACE" has any of the event codes listed in "Open" Col J for that number range.

4. Ideally, if the number ranges match and one of the event codes listed in "Open" Col J matches, then the cell in Col. J would be highlighted & the contents replaced with the event code that was found in "COA TRACE".

Example:
On "Open", row 2 I have a number range of 12345678910-12345678911, and I'm looking for events either 2960 or 2620.
When I look at "COA TRACE", row 3, the number range matches and the event 2620 is one that we are looking for.
At this point I would like Row 2, Col. J in "Open" to change to bright yellow and the "2960;2620" to be replaced with "2620".

Thank you in advance for any help or suggestions for better ways to handle this. I know its very complicated.

 
 Experts-Exchange-Resolved-Events.xlsm
0
Comment
Question by:McQMom
  • 2
3 Comments
 
LVL 24

Accepted Solution

by:
StephenJR earned 500 total points
ID: 35159979
OK, this does something, but you'll have to check whether it is the right thing!
Sub x()
  
Dim rFind As Range, rSearch As Range, rCell As Range, v, i As Long, s As String

With Sheets("COA TRACE")
    Set rSearch = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
End With

With Sheets("Open")
    For Each rCell In .Range("M2", .Range("M" & Rows.Count).End(xlUp))
        Set rFind = rSearch.Find(what:=rCell, lookat:=xlWhole, searchformat:=False)
        If Not rFind Is Nothing Then
            s = rFind.Address
            Do
                If rFind.Offset(, 1) = rCell.Offset(, 1) Then
                    v = Split(rCell.Offset(, -3), ";")
                    For i = LBound(v) To UBound(v)
                        If Val(v(i)) = rFind.Offset(, 6) Then
                            rCell.Offset(, -3).Value = v(i)
                            rCell.Offset(, -3).Interior.Color = vbYellow
                            GoTo line1
                        End If
                    Next i
                End If
                Set rFind = rSearch.FindNext(rFind)
            Loop While rFind.Address <> s
        End If
line1:
    Next rCell
End With
     
End Sub

Open in new window

0
 

Author Comment

by:McQMom
ID: 35160079
Just gave it a shot on my example and it looks great! Let me just test it on my full file of real data.
0
 

Author Closing Comment

by:McQMom
ID: 35160534
Awesome! Thank you SO much. I wish you knew how much time this will save me!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

775 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question