Results 1 to 3 of 3

Applying filters

Threaded View

  1. #1
    Registered User
    Join Date
    09-10-2011
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    2

    Applying filters

    Hi,

    Require help in below.

    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"

     '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

    
         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 ......
    Last edited by jimz; 09-14-2011 at 07:52 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1