+ Reply to Thread
Results 1 to 14 of 14

Excel VBA - Autofilter, copy selection, paste to new sheet

  1. #1
    Registered User
    Join Date
    03-03-2017
    Location
    San Francisco, CA
    MS-Off Ver
    2010
    Posts
    8

    Excel VBA - Autofilter, copy selection, paste to new sheet

    I have a table with source data in columns Sheet1!A6:R553.

    In Sheet1!A3:R3, I have formulas that pull specific information out of my data table in Sheet1!A6:R553 that I want copied to a different sheet.

    Column A acts as my project name column, while column B holds ID numbers. In my case, there are multiple ID numbers per project.

    I am looking for a script to filter and loop through all the unique order numbers in Column B one by one, then copy cells A3:R3 to Sheet2!A12:R12 for as many rows as there are unique order numbers (i.e, add rows to the table).

    Example: Assume there are 5 projects in my data sheet. I will filter the data using another macro to select Project_1. I would then like a command button to active a macro that will filter to the first order number in Column B, copy Sheet1!A3:R3 to Sheet2!A12:R12, then filter to the second order number in Project_1, and repeat the process. This should go on until all unique ID numbers have been filtered and looped through.
    Last edited by Timlahaye; 03-03-2017 at 04:49 PM.

  2. #2
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Excel VBA - Autofilter, copy selection, paste to new sheet

    Hi Timlahaye,

    could you please provide sample workbook with desire output it will help us to provide better solution
    Thanks - Naveed
    -----------------------------
    If the suggestion helps you, then Click * to Add Reputation
    To Attach File: Go Advanced>>Manage Attachments>>Add Files (In Top Right Corner)>>SelectFiles>>.........Locate Your File(s)>>Upload Files>>Done (In Bottom Right)
    1. Use [code] code tags [\code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    2. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

  3. #3
    Registered User
    Join Date
    03-03-2017
    Location
    San Francisco, CA
    MS-Off Ver
    2010
    Posts
    8

    Re: Excel VBA - Autofilter, copy selection, paste to new sheet

    Hi Naveed,

    Absolutely. Here is the file: http://www.filedropper.com/highwaytemplate

    Data Sheet:
    aTPuw.png

    Empty Template Sheet:
    xwFyA.png

    Final Template (what it should look like):
    9Ukz5.png

  4. #4
    Registered User
    Join Date
    03-03-2017
    Location
    San Francisco, CA
    MS-Off Ver
    2010
    Posts
    8

    Re: Excel VBA - Autofilter, copy selection, paste to new sheet

    Bumping for visibility.

  5. #5
    Registered User
    Join Date
    03-03-2017
    Location
    San Francisco, CA
    MS-Off Ver
    2010
    Posts
    8

    Re: Excel VBA - Autofilter, copy selection, paste to new sheet

    Bumping again for visibility. Anyone able to help?

  6. #6
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Excel VBA - Autofilter, copy selection, paste to new sheet

    Hi Timlahaye,

    could you please attached sample workbook here, as i do not have access to other sites.

  7. #7
    Registered User
    Join Date
    03-03-2017
    Location
    San Francisco, CA
    MS-Off Ver
    2010
    Posts
    8

    Re: Excel VBA - Autofilter, copy selection, paste to new sheet

    Naveed,

    I'll have to upload the file later. I can't attach the file on my work computer. I do think I solved 98% of the problem.

    The issue right now is LR3 is on RegionSummary, finding the last row. Nothing (according to the code) exists on RegionSummary, so it only applies the pasted value to row LR3+1 in Column A. That doesn't change, so it keeps overwriting. I believe if the code can Dim LR3 outside of the loop, then reDim inside of the loop, it might work. Any idea how to accomplish this?

    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Excel VBA - Autofilter, copy selection, paste to new sheet

    you should of posted this in VBA section
    you may have attracted more attention there

    Put this code in Module 4
    made many comments so you should be able to follow

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by humdingaling; 03-07-2017 at 07:03 PM. Reason: grammar
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  9. #9
    Registered User
    Join Date
    03-03-2017
    Location
    San Francisco, CA
    MS-Off Ver
    2010
    Posts
    8

    Re: Excel VBA - Autofilter, copy selection, paste to new sheet

    @humdingaling,

    You sir, are a flipping genius. Thank you so much for this!

  10. #10
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Excel VBA - Autofilter, copy selection, paste to new sheet

    re-looking at it
    you may run into a little bit of problem with Ws3.column I if in circumstance there is old highway ID that doesnt get removed

    so suggest you clear ws3.column I before pasting new data there either manually before running or inside the code itself

    also may want to look at clearing the summary before running the code

    besides that its an interesting setup you have there with the formulas in ws1 row 3

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  11. #11
    Registered User
    Join Date
    03-03-2017
    Location
    San Francisco, CA
    MS-Off Ver
    2010
    Posts
    8

    Re: Excel VBA - Autofilter, copy selection, paste to new sheet

    I set up a macro to clear rows and unfilter the sheet every after each execution. And thank you again so much for your help! You're truly a life-saver.

    Regarding ws1 row 3 forumlas, I couldn't think of a better option to pull specific information out of the dataset, so I found something that worked on a basic level. Eventually it might be more simple, but for now the code you built will translate across many of my projects.

  12. #12
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Excel VBA - Autofilter, copy selection, paste to new sheet

    not a problem
    glad to help

    Thanks for the rep

  13. #13
    Registered User
    Join Date
    03-03-2017
    Location
    San Francisco, CA
    MS-Off Ver
    2010
    Posts
    8

    Re: Excel VBA - Autofilter, copy selection, paste to new sheet

    humdingaling,

    Just a question for you. One of the macros my output is dependent on, =MakeList typically when you filter a sheet only concatenates visible cells. When you execute this script, =makelist ends up concatenating all cells being from the column. Is there any way to insert a script to maybe "calculate" or send keys F2 & enter in between loops on cells in row 3 that have =makelist as a formula?

  14. #14
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Excel VBA - Autofilter, copy selection, paste to new sheet

    not quite sure what your example is meant to do
    maybe try this
    http://analysistabs.com/vba-code/worksheet/m/calculate/

    VBA Calculate Worksheet Method: In Specified Range

+ 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. Autofilter, copy from sheet 1 and paste to sheet2, delete previous info on sheet 2
    By leigh12483 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-30-2015, 08:21 PM
  2. Autofilter database,copy paste result in another workbook sheet
    By Mr. Confused in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-10-2015, 10:29 AM
  3. copy, paste rows to new sheet using autofilter macro
    By Mr. Confused in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-09-2015, 05:00 AM
  4. Copy Filitered Selection and Paste into another Sheet
    By gammaman in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-17-2013, 05:35 AM
  5. [SOLVED] Based on a selection copy and paste data to another sheet
    By Spherous in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-31-2013, 01:17 AM
  6. copy, paste rows to new sheet using autofilter macro
    By cvsuryam in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-06-2011, 07:26 AM
  7. Replies: 3
    Last Post: 11-12-2010, 04:31 AM

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