+ Reply to Thread
Results 1 to 7 of 7

Need a way to automate filtering and copying from many different columns

  1. #1
    Registered User
    Join Date
    10-26-2015
    Location
    JC, TN
    MS-Off Ver
    Office 365 for Enterprise version 2208
    Posts
    41

    Need a way to automate filtering and copying from many different columns

    I'm new at macros and have been able to figure out a lot, but I don't even know where to start here. I've attached a portion of my .xlsm file.
    What I need is a macro that will take data from Sheet1 and copy it to Sheet2, beginning at cell A2.
    The problem is the specific data that I need copied over. I'm even having trouble wording this so it's easily understandable. Here we go:
    For every column header "If failed new SR#", if a cell in each of those columns has a number in it, I need that number copied and pasted to Sheet2 IF AND ONLY IF the cell that is two cells to the right of it is blank.
    Sheet2 column A will end up being a list of all of these numbers that have no date two cells to the right of it.

    Examples from the attached file:
    Cell R72 has a number in it. Cell T72 is blank. I need the number in cell R72 copied and pasted to Sheet2 beginning at cell A2.
    Cell N93 has a number in it. Cell P93 is blank. I need the number in cell N93 copied and pasted to Sheet2 column A in the next available cell.
    And so on until all of the "If failed new SR#" cells that do not have a "Date Installed" two columns over are copied into the list on Sheet2.

    I really hope this makes sense, but I'm not even sure it's possible to do.
    If this is possible, I would really appreciate some help because I'm having to do this manually right now and it takes some time filtering these columns down and copying the SR#'s I need one at a time.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    07-14-2017
    Location
    Poland
    MS-Off Ver
    Office 2010
    Posts
    536

    Re: Need a way to automate filtering and copying from many different columns

    Try something like this.
    Please Login or Register  to view this content.
    Last edited by maras_mak; 05-16-2020 at 01:34 AM.
    Best Regards,
    Maras.

  3. #3
    Registered User
    Join Date
    10-26-2015
    Location
    JC, TN
    MS-Off Ver
    Office 365 for Enterprise version 2208
    Posts
    41

    Re: Need a way to automate filtering and copying from many different columns

    Thanks for the quick reply Maras! Sorry for the delay in applying what you gave me. It's been pretty hectic the last few days and I haven't actually run this report since I posted for help.

    I assigned your code to a button on a 3rd sheet and ran it. I made no changes. All I get after a couple seconds is the MsgBox "All SRs are closed". Nothing is on Sheet2.

    Also, I'm not sure if this is worth noting because your code is WAY above my level (so far above that I'm having trouble following exactly what it's doing) , but I want to point out that there are two sets of numbers in the columns that are side by side:
    The "If failed new SR#" and the "If failed new Order#" columns are always side by side and the numbers are always in the same format. How does your code here differentiate between the numbers in those two columns using ptrn = "#[-]##########" (I'm just curious and trying to learn something here).

    Thanks for the help so far!!
    Regards,
    Possum

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this Excel basics demonstration !


    According to your attachment as a VBA beginner starter :

    PHP Code: 
    Sub Demo1()
           Const 
    "IF(¤=""If failed new SR#"",COLUMN(¤))""Sheet2"
             
    Dim V
             Application
    .ScreenUpdating False
             Sheets
    (S).UsedRange.Offset(1).Clear
        With Sheets
    ("Sheet1").UsedRange.Columns
            
    For Each V In Filter(.Parent.Evaluate(Replace(F"¤", .Rows(1).Address)), FalseFalse)
               .
    Range("AK2").Formula "=AND(NOT(ISBLANK(" & .Cells(2Val(V)).Address(00) & _
                                             
    ")),ISBLANK(" & .Cells(2Val(V) + 2).Address(00) & "))"
               
    .AdvancedFilter xlFilterInPlace, .Range("AK1:AK2")
               .
    Item(Val(V)).Offset(1).Copy Sheets(S).Cells(Rows.Count1).End(xlUp)(2)
            
    Next
               
    .Range("AK2").Clear
            
    If .Parent.FilterMode Then .Parent.ShowAllData
        End With
             Application
    .ScreenUpdating True
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb Try this !


    According to your attachment another fast demonstration :

    PHP Code: 
    Sub Demo2()
        
    Dim L&, VC%, R&
            
    1
            V 
    Sheets("Sheet1").UsedRange.Value2
            Application
    .ScreenUpdating False
        With Sheets
    ("Sheet2")
            .
    UsedRange.Offset(1).Clear
        
    For 1 To UBound(V2)
            If 
    V(1C) = "If failed new SR#" Then
                
    For 2 To UBound(V)
                    If 
    IsEmpty(V(R2)) Then If Not IsEmpty(V(RC)) Then L 1: .Cells(L1).Value2 V(RC)
                
    Next
            End 
    If
        
    Next
            Application
    .ScreenUpdating True
        End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  6. #6
    Registered User
    Join Date
    10-26-2015
    Location
    JC, TN
    MS-Off Ver
    Office 365 for Enterprise version 2208
    Posts
    41

    Re: Try this !

    Quote Originally Posted by Marc L View Post

    According to your attachment another fast demonstration :

    PHP Code: 
    Sub Demo2()
        
    Dim L&, VC%, R&
            
    1
            V 
    Sheets("Sheet1").UsedRange.Value2
            Application
    .ScreenUpdating False
        With Sheets
    ("Sheet2")
            .
    UsedRange.Offset(1).Clear
        
    For 1 To UBound(V2)
            If 
    V(1C) = "If failed new SR#" Then
                
    For 2 To UBound(V)
                    If 
    IsEmpty(V(R2)) Then If Not IsEmpty(V(RC)) Then L 1: .Cells(L1).Value2 V(RC)
                
    Next
            End 
    If
        
    Next
            Application
    .ScreenUpdating True
        End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    @Marc L: This seems to work perfectly!! It also makes me realize exactly how much I still need to learn. At first glance, I can't follow this code at all.
    Merci mon ami.

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Need a way to automate filtering and copying from many different columns


    Thanks for the rep' !

    Both demonstrations use exactly the same logic, first one just applies some Excel basics like any beginner operating manually …

+ 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. [SOLVED] Copying a filtering table is copying everything if that filtered item does not exist.
    By taylorsm in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-12-2018, 09:14 AM
  2. Replies: 1
    Last Post: 11-12-2016, 05:13 PM
  3. Automate hiding columns, adding columns, inserting formulas, and filtering
    By hpatel517 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-27-2016, 11:17 AM
  4. Running a Query to Automate Filtering on a Separate Sheet
    By StevenJRossi in forum Excel General
    Replies: 1
    Last Post: 06-07-2016, 08:13 AM
  5. Copying only particular columns after filtering data
    By irishman311 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-27-2012, 07:53 AM
  6. Filtering data and copying across certain columns
    By muhl in forum Excel General
    Replies: 2
    Last Post: 03-10-2011, 06:57 PM
  7. Replies: 0
    Last Post: 08-16-2007, 05:51 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