+ Reply to Thread
Results 1 to 4 of 4

Automatically copy rows to another sheet based on criteria, when original sheet is updated

  1. #1
    Registered User
    Join Date
    06-28-2016
    Location
    California, United States
    MS-Off Ver
    MS Office 2010
    Posts
    2

    Automatically copy rows to another sheet based on criteria, when original sheet is updated

    Hi,

    I am a complete beginner when it comes to Excel VBA and am really struggling to find a solution to my problem. Here is in essence, what my problem consists of:

    I have a .xlsm file that is made of several spreadsheets. Let's say I have a main spreadsheet titled "Main Sheet", and a secondary sheet titled "Other Sheet One" that will contain a subset of the rows of "Main Sheet".

    Let's say Main Sheet consists of a table that looks like:

    -------------------------------------
    | Animal | Color_ | Number | Food__ |
    ------------------------------------
    | Dog___ | Green_ | 1_____ | Egg___ |
    ------------------------------------
    | Cat___ | Pink__ | 10____ | Cheese |
    ------------------------------------
    | Mouse_ | Red___ | 11____ | Bread_ |
    ------------------------------------
    | Bird__ | Green_ | 100___ | Milk__ |
    ------------------------------------
    | Fish__ | Blue__ | 101___ | Rice__ |
    -------------------------------------


    And a formula just beneath it that takes the cumulative sum of column 'C' (number) in cell 'C7' (let's say that the table fills rows 1 through 6).

    You'll have to excuse the underscores. I couldn't figure out how to align them with whitespace.

    Anyways, and let's say that "Other Sheet One" is composed of just the header of "Main Sheet" (that is, the row [Animal, Color, Number, Food]) located at row 1, and the same cumulative sum formula immediately beneath it in column 'C' (thus it would be in 'C2').

    I wish to be able to, either whenever I update "Main Sheet" or maybe have a button existing in either "Main Sheet" or "Other Sheet One" which when I click (whichever would be easier/better), would clear currently existing values of "Other Sheet One", then update "Other Sheet One" to fill up with rows (starting from just below the header and above the cumulative sum formula in "Other Sheet One") from "Main Sheet" that have a color equal to "Red", "Green", or "Blue".

    Would this be possible to do? This problem is very difficult for me, because I am unable to figure out how to extract row data based on multiple criteria to another spreadsheet, while shifting existing formulas down as those extracted rows are pulled in. Also, because the solution would need to take care of updating "Other Sheet One" in the scenario of adding new or deleting old rows from "Main Sheet" (by what I assume would be accomplished by the deleting of all values of "Other Sheet One", and writing all the new rows in from "Main Sheet").

    Help would be greatly appreciated. Thanks in advance.

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Automatically copy rows to another sheet based on criteria, when original sheet is upd

    It would be very helpful if you can come up with a sample file consisting of both worksheets.

    Is it always only "Red" + "Green" + "Blue"? Or will this vary?
    多么想要告诉你 我好喜欢你

  3. #3
    Registered User
    Join Date
    06-28-2016
    Location
    California, United States
    MS-Off Ver
    MS Office 2010
    Posts
    2

    Re: Automatically copy rows to another sheet based on criteria, when original sheet is upd

    I provided that particular example as I felt that it represented a general case well enough. "Red", "Green", and "Blue" was just for the purpose of filtering rows based on matching column 'B' values against 3 different strings at the same time (when I actually intend to apply it, it will be against 3 other strings).

    In the example that I provide, I want to be able to update "Main Sheet" (either by deleting or adding a new row entry), and have "Other Sheet One" update by criteria. The "Desired Result" is an example of how "Other Sheet One" would look like if the script works properly on the current "Main Sheet".
    Attached Files Attached Files

  4. #4
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Automatically copy rows to another sheet based on criteria, when original sheet is upd

    You may think you have explained fully, true, but it is still better to have an example file provided.

    Not only it becomes much clearer what you need with a Before & After results,
    people who is going to help you can immediately test the code and see if it works too, without having to generate/type out dummy data to test on,
    and you wouldn't have to type all that data out too.

    I've gone ahead with the button method, because using the Change event for such updates might make it clunky when you start having too much data.
    This is also assuming your data is not going to be too large.
    In case your data is going to be huge (always >10000 rows), we would need to use another approach to this.
    Attached Files Attached Files

+ 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] Automatically copy rows to another sheet if criteria filled
    By njf1994 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-18-2015, 06:01 AM
  2. Copy complete rows matching criteria to another sheet automatically
    By abdulahadzafar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-05-2014, 12:09 PM
  3. Copy rows to a given sheet based on several criteria
    By bfora in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-02-2013, 11:12 AM
  4. Replies: 4
    Last Post: 07-24-2012, 07:09 AM
  5. Copy rows to a sheet based on criteria
    By Belo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-27-2010, 06:03 PM
  6. Copy rows with criteria to different sheet & automatically add formula
    By Andrea C in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-12-2009, 01:21 PM
  7. Links don't get automatically updated in a sheet copy?
    By StargateFanFromWork in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-07-2005, 03:10 PM

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