Macro to find Like and paste values

AFANPQ

New Member
Joined
Apr 25, 2019
Messages
13
Hello,

This is my first post. I am fairly new to VBA and this has me in over my head. I have scoured the internet to try and find the answer for my issue. I am trying to write a script to reference column "S" by row ("S2", "S3", "S4" to the end of the list) and find Like values in Ranges "D2:D500", "F2:F500", and "M2:M500". If matches are found I'd like to paste all of the matches into column "A".

Example:
A ............ D F ........ M.............. S
Lettuce, Onions Mayo Pickles Onions Lettuce, Onions Mayo Pickles Burger w/ Pickles Pickles
Burger w/ Pickles

I'm not sure if I'm making total sense. Please ask if you need clarity!
 
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Possible Relationship[/TD]
[TD][/TD]
[TD][/TD]
[TD]Proj. Name[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Project5
Project7<strike></strike><strike></strike>[/TD]
[TD]<strike></strike>[/TD]
[TD][/TD]
[TD]Project1[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]Project1
Project7<strike></strike><strike></strike><strike></strike>[/TD]
[TD]<strike></strike>[/TD]
[TD][/TD]
[TD]Project5[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]Project1 <strike></strike>
Project5[/TD]
[TD]<strike></strike><strike></strike>[/TD]
[TD][/TD]
[TD]Project7<strike></strike>[/TD]
[/TR]
</tbody>[/TABLE]
This code is working. But it's not listing every match within the corresponding cells. I'm sure it's my fault for not giving the best detail and examples.
I'm not sure how I can express exactly what I'm looking for but I'll give it a go...

Column "S" holds the search criteria.... I need the code to search the aforementioned columns to find the partial value of "S2". Let's say the value is found in 3 different rows (2, 6 and 8). The projects identified in Column "D" for each of these rows would be listed within Cells "A2", "A6" and "A8". However, "Project7" would not be on the list in row 8 column A because it is the return value on that row and doesn't need to be listed in the same row.

After the "S2" search completes the code would continue "S3", "S4" to the end of Column S completing all of the lists within column "A"

I hate to be a pain. Thank you for giving this a try!
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
this will be my last effort without being able to see the worksheet.

Code:
Sub t9()
Dim rng As Range, fn As Range, c As Range, r As Range
Set rng = Union(Range("F2:G500"), Range("M2:M500"))
    For Each c In Range("S2", Cells(Rows.Count, "S").End(xlUp))
        For Each r In rng
            If InStr(r.Value, c.Value) > 0 Then
                If r.Value <> .Cells(r.Row, "D").Value Then
                    Cells(r.Row, 1) = Cells(r.Row, 1) & vbLf & Cells(r.Row, "D").Value
                End If
            End If
        Next
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,832
Messages
6,181,231
Members
453,026
Latest member
cknader

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top