Applying filters

jimz

New Member
Joined
Sep 10, 2011
Messages
1
Hi,

Require help in below.

Code:
Option Explicit

Sub CopyColumnByTitle()
    Dim t As Range, rng As Range
'Replace India with ind
 
Columns("F:F").Select
    Selection.Replace What:="India", Replacement:="ind", lookat:= _
        xlWhole, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
        ReplaceFormat:=False
      

       
'Replace Blank cells with NY
       
Columns("F:F").Select
    Selection.Replace What:="", Replacement:="NY", lookat:= _
        xlWhole, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
        ReplaceFormat:=False
        
      '-------------------------------------------
        With Sheets(1).Rows(1)
        Set t = .Find("Name", lookat:=xlPart)
        If Not t Is Nothing Then
            Sheets(1).Columns(t.Column).EntireColumn.Copy _
            Destination:=Sheets(2).Columns(1)
        Else
            MsgBox "Title Not Found"
            Exit Sub
        End If
    End With
    
    '-------------------------------------------
        With Sheets(1).Rows(1)
        Set t = .Find("Version", lookat:=xlPart)
        If Not t Is Nothing Then
            Sheets(1).Columns(t.Column).EntireColumn.Copy _
            Destination:=Sheets(2).Columns(2)
        Else
            MsgBox "Title Not Found"
            Exit Sub
        End If
    End With
    
    '-------------------------------------------
        With Sheets(1).Rows(1)
        Set t = .Find("Address", lookat:=xlPart)
        If Not t Is Nothing Then
            Sheets(1).Columns(t.Column).EntireColumn.Copy _
            Destination:=Sheets(2).Columns(3)
        Else
            MsgBox "Title Not Found"
            Exit Sub
        End If
    End With

the above code allows me to copy the data to sheet2 "the code is huge so not able to past every thing"

Code:
 'now appling the filter crateria on the sheet2 and past the data on sheet3
    
    '~~> This will filter the data for names which equals Hary and John
     With Sheets(2).Range("B1")
        .AutoFilter Field:=1, Criteria1:="=Hary", _
        Operator:=xlOr, Criteria2:="=John"
        '~~> Copy the filtered range to sheet 3
        With Sheets(2).AutoFilter.Range
            On Error Resume Next
            Set rng = .Range("A1") _
            .SpecialCells(xlCellTypeVisible)
            On Error GoTo 0
            If Not rng Is Nothing Then rng.Copy Sheets(3).Range("A1")
        
        End With
    End With
'now appling the filter crateria on the sheet2 and past the data on sheet3
till here have no problem


now after data is pasted on the sheet 3 from sheet 2 i need to go back to the sheet 2 change filter criteria and past the data to sheet4. which i am not able to do so.

Also need copy some columns only from sheet2 but the entire sheet gets pasted to the sheet3

Code:
     With Sheets(2).Range("J1")
        .AutoFilter Field:=10, Criteria1:="=Analyst - Query Raised"
        '~~> Copy the filtered range to sheet 3
        With Sheets(2).AutoFilter.Range
            On Error Resume Next
            Set rng = .Range("A1") _
            .SpecialCells(xlCellTypeVisible)
            On Error GoTo 0
            If Not rng Is Nothing Then rng.Copy Sheets(4).Range("A1")
        
        End With
    End With
    
    
End Sub

The problem is i need to copy the data from sheet2 to sheet3 sheet4 sheet5 and sheet6 with different filter Criteria.


I also need to copy only some specific columns from sheet2 to sheet3.

please can some one help me it is urgent ......
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,224,602
Messages
6,179,841
Members
452,948
Latest member
UsmanAli786

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