?
Solved

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

Posted on 2011-03-17
3
Medium Priority
?
464 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 24

Accepted Solution

by:
StephenJR earned 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

764 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