+ Reply to Thread
Results 1 to 3 of 3

Filter and Copy Skipping Some Values

Hybrid View

  1. #1
    Registered User
    Join Date
    11-10-2016
    Location
    Dallas, Texas
    MS-Off Ver
    Office 2013
    Posts
    5

    Filter and Copy Skipping Some Values

    Hi Y'all,

    I made a sub to copy and paste filtered excel data from one worksheet to another. It works for the most part, but on the function calls with an array the sub is skipping over the 4 starting values. Does this have to do with how I'm structuring my loop that runs over the array? Any help would be great, thanks!


    
    Sub FilterAndCopy(sht As Worksheet, target As Worksheet, filterValue As String, filterRange As String)
        
        Dim lastRow As Long
        Dim selectFilterRange As range
        Dim copyRange As range
        Dim regEx As New RegExp
        Dim arr() As String
        
        'Filter and copy membership stats
        sht.AutoFilterMode = False
        lastRow = sht.range("A" & sht.Rows.Count).End(xlUp).Row
        Set selectFilterRange = sht.range(filterRange & lastRow)
        Set copyRange = sht.range("A2:K" & lastRow)
            
        'Block below finds if multiple filter values are used
        With regEx
            .Global = True
            .MultiLine = True
            .IgnoreCase = False
            .Pattern = "[,]"
        End With
            
        If regEx.TEST(filterValue) Then
            arr() = Split(filterValue, ",")
            Dim i As Integer
            For i = LBound(arr) To UBound(arr)
                selectFilterRange.AutoFilter Field:=11, Criteria1:=arr(i)
                copyRange.SpecialCells(xlCellTypeVisible).Copy target.range("A2")
            Next i
        Else
            selectFilterRange.AutoFilter Field:=11, Criteria1:=filterValue
            copyRange.SpecialCells(xlCellTypeVisible).Copy target.range("A2")
        End If
            
        sht.ShowAllData
            
       End Sub
    
        'Call outside sub for each sheet in book
        FilterAndCopy Sheets("Donations by Transaction"), Sheets("Memberships"), "TPWF Membership", "A1: K"
        FilterAndCopy Sheets("Donations by Transaction"), Sheets("Donations"), "TPWF Annual Funds, Lone Star Land Steward", "A1: K"
        FilterAndCopy Sheets("Donations by Transaction"), Sheets("SOTW"), "Stewards of the Wild", "A1: K"
        FilterAndCopy Sheets("Donations by Transaction"), Sheets("Pivot Table"), "TPWF Annual Funds, Lone Star Land Steward", "A1: K"
    Thanks!
    Jordan

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2507 (Windows 11 Home 24H2 64-bit)
    Posts
    91,792

    Re: Filter and Copy Skipping Some Values

    Moved thread to the appropriate section of the forum.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    11-10-2016
    Location
    Dallas, Texas
    MS-Off Ver
    Office 2013
    Posts
    5

    Re: Filter and Copy Skipping Some Values

    Thanks, sorry about that, still new.

+ 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. copy values from columns to rows while skipping empty columns...
    By EricCy in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-10-2016, 06:20 AM
  2. copy range from one sheet to another and then copy 5 times skipping ten rows
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-13-2015, 01:35 PM
  3. [SOLVED] Excel 2007-Adv Filter Copy and Loop with Nested Autofilter Using Values from Adv Filter
    By Southfish in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-17-2014, 02:07 AM
  4. Copy Paste Macro with Values & Skipping Blanks
    By Blockey in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-30-2012, 08:24 AM
  5. Filter code skipping a line
    By jad70 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-07-2009, 04:54 AM
  6. Filter function; copy values to another sheet
    By Gert-Jan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-24-2006, 03:50 PM
  7. Filter function; copy values to another sheet
    By jgmiddel in forum Excel General
    Replies: 0
    Last Post: 04-24-2006, 12:15 PM

Tags for this Thread

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