+ Reply to Thread
Results 1 to 4 of 4

Copy Cells to another Worksheet Based on Multi Criteria

Hybrid View

  1. #1
    Registered User
    Join Date
    03-25-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    9

    Copy Cells to another Worksheet Based on Multi Criteria

    I read this thread that almost as the code that i need.

    Sub Macro2()
     
    Dim ws As Worksheet
     
    Application.ScreenUpdating = False
    
    For Each ws In Worksheets
        If ws.Name <> "Data" Then
            With Sheets("Data")
                .Range("A1").AutoFilter field:=7, Criteria1:=ws.Name
                .AutoFilter.Range.Offset(1).Copy ws.Range("A2")
                .ShowAllData
            End With
        End If
    Next ws
    
    Sheets("Data").AutoFilterMode = False
    
    Application.ScreenUpdating = True
        
    End Sub
    As the original author i want to paste only column A to E (without the field criteria column).
    Please, someone can point me to changes that i have to make!?
    Thanks in advance,
    Luís

  2. #2
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Copy Cells to another Worksheet Based on Multi Criteria

    Hi,

    please check the attached sample which contains test data from the other thread you mentioned and adapted code to copy only columns A-E: CopyToSeparateSheetsWithCondition.xls
    if you need to change the number of columns again do this in "Resize(, 5)" where 5 is the number of columns starting at A

    code:
    Option Explicit
    
    Sub CopyToSheets()
        Dim xlWs As Worksheet
         
        Application.ScreenUpdating = False
        
        With ThisWorkbook.Worksheets("Data")
            For Each xlWs In ThisWorkbook.Worksheets
                If xlWs.Name <> .Name Then
                    .Range("A1").AutoFilter Field:=7, Criteria1:=xlWs.Name
                    .AutoFilter.Range.Offset(1).Resize(, 5).SpecialCells(12).Copy xlWs.Range("A2")
                    .ShowAllData
                End If
            Next xlWs
            .AutoFilterMode = False
        End With
        
        Application.ScreenUpdating = True
    End Sub
    Please use [CODE]-TAGS
    When your problem is solved mark the thread SOLVED
    If an answer has helped you please click to give reputation
    Read the FORUM RULES

  3. #3
    Registered User
    Join Date
    03-25-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Copy Cells to another Worksheet Based on Multi Criteria

    Hi tehneXus,

    Just now i saw your reply. Your code works better for me I think.

    Thanks

  4. #4
    Registered User
    Join Date
    03-25-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Copy Cells to another Worksheet Based on Multi Criteria

    I think I got it!
    I´m using this:
     If ws.Name <> "Data" Then
            With Sheets("Data")
                .Range("C5").AutoFilter field:=4, Criteria1:=ws.Name
                .AutoFilter.Range.Offset(1).Columns(1).Copy ws.Range("B5")
                .AutoFilter.Range.Offset(1).Columns(2).Copy ws.Range("C5")
                .AutoFilter.Range.Offset(1).Columns(3).Copy ws.Range("D5")
                .ShowAllData
            End With
        End If
    Must test more to see if it works!

+ Reply to Thread

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