Need to filter worksheet by Cells that Contain specific characters

mstuf

Active Member
Joined
Feb 4, 2003
Messages
321
Office Version
  1. 2016
Platform
  1. Windows
Good Evening -- I have a spreadsheet that I need to filter and display rows that in a specifued Column, CONTAIN specified Character Values.

IE I Need to filter and display ( preferably in a seperate sheet ) all rows that contain CD in Column AK . Typical Values in that column would be CD International - Box Set CD & DVD - CD Rock - LP Blues - VHS Music Rock - Book Paperback Science Biology - Cassette Jazz - Audio CD Fiction Humor - etc.



After doing the Advanced Filter Tutorials and then searching for the syntax to define Contains, I have found that filtering by "Contains" feature is N/A.

Would someone be kind enough to share knowledge and give me some ideas of where to look next for the best way to do this. My Excel Skills are some above beginner but, by no means advanced.

Thank You
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Good Evening -- I have a spreadsheet that I need to filter and display rows that in a specifued Column, CONTAIN specified Character Values.

IE I Need to filter and display ( preferably in a seperate sheet ) all rows that contain CD in Column AK . Typical Values in that column would be CD International - Box Set CD & DVD - CD Rock - LP Blues - VHS Music Rock - Book Paperback Science Biology - Cassette Jazz - Audio CD Fiction Humor - etc.



After doing the Advanced Filter Tutorials and then searching for the syntax to define Contains, I have found that filtering by "Contains" feature is N/A.

Would someone be kind enough to share knowledge and give me some ideas of where to look next for the best way to do this. My Excel Skills are some above beginner but, by no means advanced.

Thank You

Hi mstuf:

Let us have a look at the following illustration ...
Book4
ABCDEFGH
1Field1Field2Field3database
2A_1Box CDC_15criteriaRange
3A_2CDC_2copyToRange
4A_3MusicC_3
5A_4Music CDC_4Field2Field3
6A_5SongsC_5Box CDC_1
7A_6ultraC_6CDC_2
8A_7technoC_7Music CDC_4
9A_8jazzC_8Jay CD KayC_9
10A_9Jay CD KayC_9CDs galoreC_10
11A_10CDs galoreC_10
12A_11Sony MusicC_11
13
Sheet1


I have used computed criterion with the following formula in cell E2 ...

=FIND("CD",B2)

I hope this helps.
 
Upvote 0
then searching for the syntax to define Contains

hi,

When you apply an autofilter on this column, try specifying the syntax '*CD*' (without quotes) in the "Contains" option and then do a filter. It should work.
 
Upvote 0
Thank you both for the ideas -- I am at work now but will be home a little later to experiment with those ideas and see what works for me.

Again - Thank you - I really appreciate all the help this board has provided.
 
Upvote 0
Try this code:

Sub CopyMatchingLines()

Dim lngX As Long
Dim lngY As Long
Dim lngLastDataRow As Long
Dim strInputWorksheet As String
Dim strOutputWorksheet As String
Dim strFilterFor As String
Dim strFilterColumn As String

'Set parameters
strInputWorksheet = "Sheet1"
strOutputWorksheet = "Sheet2"
strFilterFor = "CD"
strFilterColumn = "AK"

'Delete all data on target worksheet
Worksheets(strOutputWorksheet).Select
Cells.Clear
Range("A1").Select

'Copy data from input worksheet to target worksheet
Worksheets(strInputWorksheet).Select
lngLastDataRow = ActiveCell.SpecialCells(xlLastCell).Row

lngY = 0
For lngX = 1 To lngLastDataRow
If InStr(Range(strFilterColumn & CStr(lngX)), strFilterFor) > 0 Then
lngY = lngY + 1
Sheets(strInputWorksheet).Rows(lngX).Copy
Sheets(strOutputWorksheet).Select
Rows(lngY).Select
Range("A" & CStr(lngY)).Activate
ActiveSheet.Paste
Worksheets(strInputWorksheet).Select
End If
Next
End Sub
 
Upvote 0
Good Evening -- I have a spreadsheet that I need to filter and display rows that in a specifued Column, CONTAIN specified Character Values.

IE I Need to filter and display ( preferably in a seperate sheet ) all rows that contain CD in Column AK . Typical Values in that column would be CD International - Box Set CD & DVD - CD Rock - LP Blues - VHS Music Rock - Book Paperback Science Biology - Cassette Jazz - Audio CD Fiction Humor - etc.



After doing the Advanced Filter Tutorials and then searching for the syntax to define Contains, I have found that filtering by "Contains" feature is N/A.

Would someone be kind enough to share knowledge and give me some ideas of where to look next for the best way to do this. My Excel Skills are some above beginner but, by no means advanced.

Thank You


You do not need advanced filetering for this. The normal AUTOFILTERING can handle this. Do Autofilter, Custom, in the Title chose Contain then type CD in the provided field.
 
Upvote 0
SWEET -

Well, I learned something from each example -- Thank you

I think the last one is the easiest for this project -- Seems so easy now that I see it but, Nowhere in my reading Excel Help did I run across that option. I had assumed that since Contains was not an operator in advanced that it was not for Auto Either.

In trying each of the others, I find parts of those that will help with some other ideas that have been rolling around in my head wondering if or how I could do it.

Looking at the Code from pbornemeier I went thru step by step - I dont think its my answer but two routines in it are answers to other back of the brain ideas.


As Always - Amazed by how much some of you know about Excel - I like to just browse and read here while watching TV.

I got to feel smart the other day when I watched a friend working repetitivly on a work sheet and was able to set him up with a formula and 2 macros to save more 50% of his manual operations. What a Rush !!


Thanks
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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