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!
 
ABCD
1Possible RelationshipProj. Name
2Project5
Project7<strike></strike><strike></strike>
<strike></strike>Project1
3
4
5
6Project1
Project7<strike></strike><strike></strike><strike></strike>
<strike></strike>Project5
7
8Project1 <strike></strike>
Project5
<strike></strike><strike></strike>Project7<strike></strike>

<tbody>
</tbody>
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

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
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,215,327
Messages
6,124,287
Members
449,149
Latest member
mwdbActuary

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