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

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,791
Messages
6,121,611
Members
449,038
Latest member
apwr

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