How do I filter a table by partial matches using a list of values?

kittenofd00m

New Member
Joined
Dec 25, 2021
Messages
2
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
  2. Web
I have a list of patients with their prescribed medications in one table. In another I have a list of medications.

In the first table the prescriptions contain medication names, but they can also contain other text like dosages (10 mg, 15 mg, etc) and delivery type (tablet, cream, etc).

Here is an example of the data that I am working with.....

anon sample.png


I need to filter the table on the left using the list of medications on the right such that the table on the right only shows rows that contain one of the medications in the list on the right.

I know that this involves partial searches but I just cannot figure out how it should be done.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I mistyped that last part and did not see a way to correct it in the original post so here is the correction.....

I need to filter the table on the left using the list of medications on the right such that the table on the right only shows rows that contain one of the medications in the list on the right.

I know that this involves partial searches but I just cannot figure out how it should be done.
That should have said.....

I need to filter the table on the left using the list of medications on the right such that the table on the left only shows rows that contain one of the medications in the list on the right.

I know that this involves partial searches but I just cannot figure out how it should be done.
 
Upvote 0
Not knowing the names of your tables, you could try and run this macro

VBA Code:
Sub jec()
 Dim jv(), ar, sq As Variant, i As Long, j As Long, x As Long
 ar = Cells(1).CurrentRegion
 sq = Cells(1, 5).CurrentRegion
 
 For i = 2 To UBound(ar)
   For j = 2 To UBound(sq)
      If InStr(1, ar(i, 2), sq(j, 1), vbTextCompare) Then
        ReDim Preserve jv(x)
        jv(x) = ar(i, 2): x = x + 1
        Exit For
      End If
   Next
 Next
 
 Cells(1, 1).CurrentRegion.AutoFilter 2, jv, 7
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,458
Members
449,085
Latest member
ExcelError

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