Solved

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

Posted on 2011-03-17
3
456 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now