+ Reply to Thread
Results 1 to 2 of 2

audtofilter 8 spreadsheet ans if criteria is met, copy to the new spreadsheet

  1. #1
    Registered User
    Join Date
    08-18-2017
    Location
    Hong Kong
    MS-Off Ver
    Office 2016
    Posts
    1

    audtofilter 8 spreadsheet ans if criteria is met, copy to the new spreadsheet

    Hi guys,

    I am new to this forum. I am trying to have a code that allows me to filter 8 worksheets and if the condition is correct, then coy a particular column to a new spreedsheet? I have only started with 1, it filters 1 spreadsheet, but it doesnt copy to the new spreadsheet called "SOI". Why is this the case? Thank you for your help in advance!!!



    Sub copyFilteredData()

    Dim rng As Range
    Dim autofiltrng As Range


    With Sheets("General")
    .Range("A1").AutoFilter field:=5, Criteria1:="yes", Operator:=xlFilterValues
    End With


    With ActiveSheet.AutoFilter.Range
    On Error Resume Next
    Set autofiltrng = .Offset(1, 0).Resize(.Rows.Count–1, 1).SpecialCells(xlCellTypeVisible)
    On Error GoTo 0
    End With

    Worksheets(“SOI”).Range("B5:B22").Cells.Clear

    If autofiltrng Is Nothing Then
    MsgBox “no data available for copying!”


    Else

    Set rng = ActiveSheet.AutoFilter.Range

    rng.Offset(1, 0).Resize(rng.Rows.Count–1).Copy Destination:=Worksheets("SOI").Range(“A2”)

    End If

    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: audtofilter 8 spreadsheet ans if criteria is met, copy to the new spreadsheet

    You need to check which sheet is active when you use the ActiveSheet object. It's best to declare your sheets explicitly.

    Try:

    Please Login or Register  to view this content.
    Design everything to be as simple as possible, but no simpler.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 01-13-2016, 04:13 PM
  2. Macro button to possibly copy certain criteria to a new spreadsheet
    By aaaaaaiden in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-15-2013, 02:22 PM
  3. [SOLVED] Copy and paste to new spreadsheet based in date and other criteria are met VBA
    By andie2013 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-15-2012, 01:29 PM
  4. Program to copy certain data that meets criteria into new spreadsheet?
    By hellokitty123 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-02-2010, 08:48 PM
  5. Replies: 1
    Last Post: 07-30-2010, 10:01 PM
  6. copy certain cells from 1 spreadsheet to other spreadsheet depending on condition
    By Gauntsghost in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-14-2010, 07:06 PM
  7. Copy data from spreadsheet to new worksheet in different spreadsheet.
    By Davie1982 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-19-2007, 11:38 AM

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