Filter data

Steffmeister

Board Regular
Joined
Nov 7, 2005
Messages
195
Hi guys,

I have data in Excel and want to filter cells which contains 'dyn'.
The cells with the name dyn in it must copied in sheet 2. In sheet1 must those addresses deleted. Must this be done with a macro?
Can somebody help me?

Tnx for now

Steffmeister
 
Hi Steffmeister:

The following macro will filter the data in column A of Sheet1 for dyn and hursley, copy theseto cell A5 of Sheet2 and cell C1 of Sheet1
Code:
Sub ySteff()
' Data to be filtered is in Sheet1 ... cells A1 down
    Sheets("sheet2").Activate
'incorporating Filter Criterion
    Sheets("sheet2").Range("c2").Formula = "=FIND(""dyn"",A2)"
    Sheets("sheet2").Range("C3").Formula = "=FIND(""hursley"",A2)"
    Sheets("Sheet1").Range("A:A").AdvancedFilter Action:=xlFilterCopy, _
        CriteriaRange:=Range("C1:C3"), CopyToRange:=Sheets("Sheet2").Range("A5"), Unique:=False
    'data without dyn's will be copied to column C of Sheet1 (it can of course be copied to column A ...
    'I want to retain the original data ... just in case
    Sheets("sheet2").Range("a5", Range("a5").End(xlDown)).Copy [sheet1!C1]
End Sub
In the following illustration, the data to be filtered is in column A of Sheet1 ...
y051113h1.xls
ABCD
1Field1Field1
2jindyn
3mindyn
4dynhursley
5bin
6flyn
7raoul
8beth
9dyn
10floe
11hursley
12ben
13
Sheet1


Following is Sheet2 with C1:C3 as the criteria range, and the data filtered from Sheet2 is displayed in cell A5 and down
y051113h1.xls
ABCD
1
2#VALUE!
3#VALUE!
4
5Field1
6dyn
7dyn
8hursley
9
10
11
12
13
Sheet2
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi Yogi Anand,

Tnx for the nice macro :biggrin:.
Now I got my last question :oops:. Is it possible to delete the files in sheet 1 which are copied to sheet 2?

Tnx. Grts. Steffmeister
 
Upvote 0
Steffmeister said:
Hi Yogi Anand,

Tnx for the nice macro :biggrin:.
Now I got my last question :oops:. Is it possible to delete the files in sheet 1 which are copied to sheet 2?

Tnx. Grts. Steffmeister
Hi steffmeister:

Do you mean to delete the records from column A of Sheet1? If that is what you mean, please note I copied the records that were extracted to Sheet2 to column C of Sheet1.

I don't recommend it, but you can copy the extracted records to column A of Sheet1 ... by adjusting the code as in the following ...
Code:
Sub ySteff()
' Data to be filtered is in Sheet1 ... cells A1 down
    Sheets("sheet2").Activate
'incorporating Filter Criterion
    Sheets("sheet2").Range("c2").Formula = "=FIND(""dyn"",A2)"
    Sheets("sheet2").Range("C3").Formula = "=FIND(""hursley"",A2)"
    Sheets("Sheet1").Range("A:A").AdvancedFilter Action:=xlFilterCopy, _
        CriteriaRange:=Range("C1:C3"), CopyToRange:=Sheets("Sheet2").Range("A5"), Unique:=False
    'data with dyn and hursley will be copied to column A of Sheet1 (it can of course be copied to column A ...
    'I want to retain the original data ... just in case
    Range("a5:a65536").Copy [Sheet1!A1]
End Sub
Is this what you are looking for?
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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