Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

911 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

28 Experts available now in Live!

Get 1:1 Help Now