+ Reply to Thread
Results 1 to 3 of 3

Macro Excel to copy filtered data to another sheet

  1. #1
    Registered User
    Join Date
    04-16-2013
    Location
    switzerland
    MS-Off Ver
    Excel 2003
    Posts
    8

    Macro Excel to copy filtered data to another sheet

    Hi,

    I'm very new into macro excel and I would like to copy an entire sheet after filtering and copy only the row with the name "USA"

    it is a big worksheet and if I replace "rngDest.Value = rngSource.Value
    " by "rngDest.Value = rngSource.SpecialCells(xlCellTypeVisible).Value" i get the first row replicated 1'000'000 times.

    I hope you can help me
    thanks

    ---

    Sub copycontent()

    Dim wbSource As Workbook, wbDest As Workbook
    Dim wsSource As Worksheet, wsDest As Worksheet
    Dim rngSource As Range, rngDest As Range

    Set wbSource = Workbooks.Open("test.xlsx", , True)
    Set wsSource = wbSource.Worksheets("Sheet1")
    wsSource.Range("$A$1:$H$3").AutoFilter Field:=2, Criteria1:="USA"
    Set rngSource = wsSource.Range("A:Z")

    Set wbDest = ThisWorkbook
    Set wsDest = wbDest.Worksheets("Sheet1")
    Set rngDest = wsDest.Range("A:Z")

    rngDest.Value = rngSource.Value

    wbSource.Close (False) '

    End Sub

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro Excel to copy filtered data to another sheet

    Hi, michelgirault,

    what about this code:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Macro Excel to copy filtered data to another sheet

    Untested):
    Please Login or Register  to view this content.

+ 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