search list for part of text and return all matching results and their ref !

planetsair

New Member
Joined
Jan 19, 2012
Messages
42
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hello

I have been searching for an answer but as yet have not managed to find quite the right solution, so I’m hoping someone here may be able to help me, please J
I am wanting to search (using a partial text) through a list of data (held in sheet 2) and have a formula return a list (in sheet 1) of all the ‘words’ from sheet 2 which contain that searched for text, and also their ID

Hopefully the example below will be a bit more explanatory !
In sheet 1 – I am wanting to search for CDE in sheet 2 column A,
I am wanting a list of results to show ALL the occurrences of “CDE” from sheet 2 column A
I am also wanting to have the matching ID be shown in sheet 1 column B

sheet 1
sheet 2
a
b
a
b
1
Search
1
TEXT
ID
2
CDE
2
ABCDEFGHI
SK001
3
3
HYTGREBYD
SK002
4
results
4
BCGHGICDA
SK003
5
TEXT
ID
5
CDEGHYTEGT
SK004
6
ABCDEFGHI
SK001
6
HYTSBHFR
SK005
7
CDEGHYTEGT
SK004

<tbody>
</tbody>

I don’t know if this is relevant but in reality the text will be about 20-30 characters in length and the search criteria will also be over 15 characters (rather than the ‘CDE’ shown here)

Thanks for your help in advance
Sarah
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try this macro:
Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim bottomA As Integer
    bottomA = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row
    Dim rng As Range
    Dim searchVal As String
    searchVal = InputBox("Please enter search criteria.")
    For Each rng In Sheets("Sheet2").Range("A2:A" & bottomA)
        If rng Like "*" & searchVal & "*" Then
            rng.Resize(, 2).Copy Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
        End If
    Next rng
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi Mumps

Thanks very much for this suggestion, but I’m not really wanting to use macros. Is there any other way I can do this ?

Cheers
Sarah
 
Upvote 0
Update ….

Using this
=INDEX(sheet2!A:A,MATCH("*"&$A$2&"*",sheet2!A:A,0),1)

I can get a single matching cell contents, so does anyone know how I can expand this formula so I can get all the matching cell’s contents and their respective IDs ?
 
Upvote 0
Search
CDE
results
IDXTEXTID
1ABCDEFGHISK001
4CDEGHYTEGTSK004

<COLGROUP><COL style="WIDTH: 151pt; mso-width-source: userset; mso-width-alt: 7139" width=201><COL style="WIDTH: 129pt; mso-width-source: userset; mso-width-alt: 6115" width=172><COL style="WIDTH: 48pt" width=64><TBODY>
</TBODY>


A6, control+shift+enter, not just enter, and copy down:
Rich (BB code):
=IFERROR(SMALL(IF(ISNUMBER(SEARCH($A$2,Sheet2!$A$2:$A$6)),
  ROW(Sheet2!$A$2:$A$6)-ROW(Sheet2!$A$2)+1),ROWS($A$6:A6)),"")

B6, just enter, copy across, and down:
Rich (BB code):
=IF($A6="","",INDEX(Sheet2!A$2:A$6,$A6))
 
Upvote 0
Hi Aladin
That is fantastic – just what I was wanting :) thank you :)
Just to finish it off though – how would I get the total count of the all matches obtained from the search?
Thanks
sarah
 
Upvote 0
Hi Aladin

Sorry for the slow reply – I have been away from my PC all weekend

Thanks for the new formula – that’s just what I was looking for :)
Thanks heaps
Sarah :)
 
Upvote 0

Forum statistics

Threads
1,216,025
Messages
6,128,341
Members
449,443
Latest member
Chrissy_M

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