SOLVED

Copy Data to differnt tabs quickly

%3CLINGO-SUB%20id%3D%22lingo-sub-2703129%22%20slang%3D%22en-US%22%3ECopy%20Data%20to%20differnt%20tabs%20quickly%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2703129%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20looking%20for%20a%20way%20to%20take%20a%20very%20large%20spread%20sheet%20and%20automatically%20have%20the%20data%20copied%20over%20to%20the%20appropriate%20tab.%26nbsp%3B%20Example%20find%20all%20the%20rows%20for%20Company%20Alpha%20and%20copy%20to%20its%20tab%2C%26nbsp%3BCompany%20Bravo%20and%20copy%20to%20its%20tab%2C%20Company%20Charlie%20and%20copy%20to%20its%20tab%E2%80%A6%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20macro%20copying%20and%20that%20did%20not%20work%20because%20it%20is%20not%20always%20the%20same%20number%20of%20rows%20and%20the%20same%20row%20number.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20attached%20a%20sample%20file.%26nbsp%3B%20Thanks%20for%20any%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUsing%20Windows%20platform%20and%20Excel%20365%20Apps%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2703129%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2703336%22%20slang%3D%22en-US%22%3ERe%3A%20Copy%20Data%20to%20differnt%20tabs%20quickly%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2703336%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1142425%22%20target%3D%22_blank%22%3E%40Lynette_LeJeune%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EMake%20sure%20that%20G7%20on%20the%20customer%20sheets%20equals%20G2%20on%20the%20Aging%20sheet%20-%20either%20change%20G7%20on%20all%20those%20sheets%20to%20%3CSTRONG%3EDays%3C%2FSTRONG%3E%2C%20or%20change%20G2%20on%20Aging%20to%20%3CSTRONG%3EDays%20Invoiced%3C%2FSTRONG%3E.%20Otherwise%2C%20it%20gets%20much%20more%20complicated.%3C%2FP%3E%0A%3CP%3EThen%20run%20the%20following%20macro%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-visual-basic%22%3E%3CCODE%3ESub%20SplitData()%0A%20%20%20%20Dim%20ws%20As%20Worksheet%0A%20%20%20%20Dim%20wt%20As%20Worksheet%0A%20%20%20%20Dim%20m%20As%20Long%0A%20%20%20%20Application.ScreenUpdating%20%3D%20False%0A%20%20%20%20Set%20ws%20%3D%20Worksheets(%22Aging%22)%0A%20%20%20%20m%20%3D%20ws.Range(%22E%22%20%26amp%3B%20ws.Rows.Count).End(xlUp).Row%0A%20%20%20%20ws.Range(%22O2%22).Value%20%3D%20%22Bill%20to%22%0A%20%20%20%20For%20Each%20wt%20In%20Worksheets%0A%20%20%20%20%20%20%20%20If%20wt.Name%20%26lt%3B%26gt%3B%20ws.Name%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20ws.Range(%22O3%22).Value%20%3D%20wt.Name%0A%20%20%20%20%20%20%20%20%20%20%20%20ws.Range(%22A2%3AL%22%20%26amp%3B%20m).AdvancedFilter%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Action%3A%3DxlFilterCopy%2C%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20CriteriaRange%3A%3Dws.Range(%22O2%3AO3%22)%2C%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20CopyToRange%3A%3Dwt.Range(%22A7%3AL7%22)%0A%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20Next%20wt%0A%20%20%20%20ws.Range(%22O2%3AO3%22).ClearContents%0A%20%20%20%20Application.ScreenUpdating%20%3D%20True%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2703381%22%20slang%3D%22en-US%22%3ERe%3A%20Copy%20Data%20to%20differnt%20tabs%20quickly%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2703381%22%20slang%3D%22en-US%22%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%20you%20are%20brilliant%20!%20If%20the%20customer%20names%20are%20the%20same%20on%20the%20aging%20as%20on%20the%20tabs%20does%20it%20matter%20how%20many%20I%20have%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2703414%22%20slang%3D%22en-US%22%3ERe%3A%20Copy%20Data%20to%20differnt%20tabs%20quickly%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2703414%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1142425%22%20target%3D%22_blank%22%3E%40Lynette_LeJeune%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENo%2C%20it'll%20work%20as%20long%20as%20each%20sheet%20except%20for%20the%20Aging%20tab%20corresponds%20to%20a%20customer.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2703486%22%20slang%3D%22en-US%22%3ERe%3A%20Copy%20Data%20to%20differnt%20tabs%20quickly%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2703486%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1142425%22%20target%3D%22_blank%22%3E%40Lynette_LeJeune%3C%2FA%3E%26nbsp%3BYou%20tagged%20your%20posting%20%22Office365%22.%20If%20this%20means%20you%20are%20an%20MS365%20subscriber%2C%20you%20might%20want%20to%20consider%20the%20FILTER%20function.%20The%20only%20change%20you%20would%20need%20to%20make%20is%20enter%20the%20Customer%20name%20somewhere%20on%20the%20sheet%20that%20you%20already%20named.%20In%20the%20picture%20below%20you%20see%20that%20I%20did%20that%20in%20A1.%20Could%20well%20be%20in%20F2.%20No%20need%20for%20VBA.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Screenshot%202021-08-31%20at%2017.31.39.png%22%20style%3D%22width%3A%20714px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F306975i4CD494524E018DD3%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Screenshot%202021-08-31%20at%2017.31.39.png%22%20alt%3D%22Screenshot%202021-08-31%20at%2017.31.39.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

I am looking for a way to take a very large spread sheet and automatically have the data copied over to the appropriate tab.  Example find all the rows for Company Alpha and copy to its tab, Company Bravo and copy to its tab, Company Charlie and copy to its tab…

 

I tried macro copying and that did not work because it is not always the same number of rows and the same row number.  

 

I have attached a sample file.  Thanks for any help.

 

Using Windows platform and Excel 365 Apps

6 Replies
best response confirmed by Lynette_LeJeune (New Contributor)
Solution

@Lynette_LeJeune 

Make sure that G7 on the customer sheets equals G2 on the Aging sheet - either change G7 on all those sheets to Days, or change G2 on Aging to Days Invoiced. Otherwise, it gets much more complicated.

Then run the following macro:

Sub SplitData()
    Dim ws As Worksheet
    Dim wt As Worksheet
    Dim m As Long
    Application.ScreenUpdating = False
    Set ws = Worksheets("Aging")
    m = ws.Range("E" & ws.Rows.Count).End(xlUp).Row
    ws.Range("O2").Value = "Bill to"
    For Each wt In Worksheets
        If wt.Name <> ws.Name Then
            ws.Range("O3").Value = wt.Name
            ws.Range("A2:L" & m).AdvancedFilter _
                Action:=xlFilterCopy, _
                CriteriaRange:=ws.Range("O2:O3"), _
                CopyToRange:=wt.Range("A7:L7")
        End If
    Next wt
    ws.Range("O2:O3").ClearContents
    Application.ScreenUpdating = True
End Sub

 

@Hans Vogelaar you are brilliant ! If the customer names are the same on the aging as on the tabs does it matter how many I have?

@Lynette_LeJeune 

No, it'll work as long as each sheet except for the Aging tab corresponds to a customer.

@Lynette_LeJeune You tagged your posting "Office365". If this means you are an MS365 subscriber, you might want to consider the FILTER function. The only change you would need to make is enter the Customer name somewhere on the sheet that you already named. In the picture below you see that I did that in A1. Could well be in F2. No need for VBA.

Screenshot 2021-08-31 at 17.31.39.png

Thanks @Riny_van_Eekelen! I will try this one as well!

This Option actually worked better for me as I was able to keep my formatting. Thank you both so much for your help!