VBA search function

adrianbuliga

New Member
Joined
Sep 18, 2014
Messages
2
hello,
Please help me with a code for something that…i consider…complicated :confused::confused:
To be more explicit, I’ll give you an example (my table has around 500 rows and continuously piles-up):
I have a table like this:
AB
1January31
2February28
3March31
4April30
5May31
6June30

<tbody>
</tbody>

and I want a VBA macro that will search on the B column for a specific text, let’s say „ARY”, meaning that I want to search also inside the words, not only words that begin with (as an observation some cells has more than 1 word)… and return somewhere on the sheet (or on another sheet) a new table that will contain ONLY the rows that meets the criteria. In this case would be:

AB
15January31
16February28

<tbody>
</tbody>

Thank you in advance for help,
Adrian
 

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

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
Try this for results in Columns"D & E"
Code:
[COLOR="Navy"]Sub[/COLOR] MG18Sep04
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]If[/COLOR] InStr(Dn.Value, "ary") > 0 [COLOR="Navy"]Then[/COLOR]
        c = c + 1
        Cells(c, "D") = Dn.Value
        Cells(c, "E") = Dn.Offset(, 1)
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 

vds1

Well-known Member
Joined
Oct 5, 2011
Messages
1,200
Another Method..

Code:
Sub Filter_Copy_Paste()
Dim LastRow As Long
If ActiveSheet.AutoFilterMode = True Then ActiveSheet.AutoFilterMode = False
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Sheets("Sheet1").Select
With Range("$A$1:$B$" & LastRow)
    .AutoFilter Field:=1, Criteria1:="=*ary*", Operator:=xlAnd
    .Copy Sheets("Sheet2").Range("A1")
End With
If ActiveSheet.AutoFilterMode = True Then ActiveSheet.AutoFilterMode = False
Range("A1").Select
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,598
Messages
5,832,645
Members
430,150
Latest member
amitk1

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
Top