+ Reply to Thread
Results 1 to 4 of 4

Issue copying visible cells after auto filter

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-01-2019
    Location
    New York, New York
    MS-Off Ver
    Office 2016 for Mac
    Posts
    125

    Issue copying visible cells after auto filter

    Hi guys. I have really been struggling to figure out the issue here. The copy/paste works for the first part but not the second. Here's the code and I will explain the issue afterward:

    Dim rgDel As Range
        Set rgDel = sh2.Range(Range("A2"), Range("A2").End(xlToRight).End(xlDown))
        Set rgDel = rgDel.Resize(rgDel.Rows.Count + 1, rgDel.Columns.Count).Offset(-1, 0)
            
        'Filter and copy email scores
        rgDel.AutoFilter _
        Field:=8, Criteria1:=strE1
        
         With rgDel
        .Resize(.Rows.Count + 1, .Columns.Count - 1).Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy
        End With
               
        sh3.Range("A4").PasteSpecial Paste:=xlPasteValues
        Application.CutCopyMode = False
        
         With rgDel
        .Resize(.Rows.Count + 1, .Columns.Count - 1).Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy
        End With
        
        sh3.Range("A4").PasteSpecial Paste:=xlPasteFormats
        Application.CutCopyMode = False
           
        'Filter and copy phone scores
        rgDel.AutoFilter _
        Field:=8, Criteria1:=strP1
        
        With rgDel
        .Resize(.Rows.Count + 1, .Columns.Count - 1).Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy
        End With
           
        sh3.Range("I4").PasteSpecial Paste:=xlPasteValues
        Application.CutCopyMode = False
        
        With rgDel
        .Resize(.Rows.Count + 1, .Columns.Count - 1).Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy
        End With
            
        sh3.Range("I4").PasteSpecial Paste:=xlPasteFormats
        Application.CutCopyMode = False
    NOTE: sh2 and sh3 are worksheets. strE1 and strP1 are filter criteria entered earlier with an inputbox.

    The issue is that the SECOND copy/paste does not work. It does filter so only the phone scores are showing but cannot seem to get the visible cells to copy/paste. Instead, the FIRST copied cells for email are just copied again to the second range. Please help.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Issue copying visible cells after auto filter

    It is not working because your rgDel only applies to sheet2, you need to reset it for sheet 3 if you are going to use the same variable for a range. Also at a quick glance, it looks like you are resizing your rgDel multiple times. Looks odd, but you said it is copying correctly, so I guess it is OK. I did not test it.
    Last edited by JLGWhiz; 09-05-2019 at 02:02 PM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Forum Contributor
    Join Date
    03-01-2019
    Location
    New York, New York
    MS-Off Ver
    Office 2016 for Mac
    Posts
    125

    Re: Issue copying visible cells after auto filter

    OK thank you for the idea! The weird fix, which ended up working is just inserting the copy code twice for the phone scores so that it looks like this:

    'Filter and copy phone scores
        rgDel.AutoFilter _
        Field:=8, Criteria1:=strP1
        
        With rgDel
        .Resize(.Rows.Count + 1, .Columns.Count - 1).Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy
        End With
        
        With rgDel
        .Resize(.Rows.Count + 1, .Columns.Count - 1).Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy
        End With
           
        sh3.Range("I4").PasteSpecial Paste:=xlPasteValues
        Application.CutCopyMode = False
    Is this unconventional fix related to what you mentioned? Thank you!

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Issue copying visible cells after auto filter

    Not really, but if you got it to work the way you want, then it is a good fix. MACs are weird animals anyhow.

+ 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. Get Value of First visible cell using Auto Filter
    By realniceguy5000 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-04-2017, 12:40 AM
  2. [SOLVED] What's wrong auto filter-visible rows-not copying
    By mso3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-21-2016, 01:42 AM
  3. copy, paste visible cells after Auto filter- VBA
    By meus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-31-2015, 01:59 AM
  4. Filter - Multiple Columns - Loop through Visible Rows issue
    By Vinod Krishna.C in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-11-2014, 05:30 PM
  5. Auto Filter With First Visible Cell
    By realniceguy5000 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-01-2010, 01:28 PM
  6. Sum according to Auto filter non visible cells
    By ElmerS in forum Excel General
    Replies: 9
    Last Post: 08-10-2009, 12:45 PM
  7. Replies: 4
    Last Post: 06-25-2006, 02:35 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