Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Calculating Sales Tax 13 66
create different version if file exists 1 44
Combining match and vlookup??? 4 27
Zip Codes Excel Spreadsheet 4 24
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

732 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