+ Reply to Thread
Results 1 to 7 of 7

How to copy entire row based on criteria

  1. #1
    Registered User
    Join Date
    03-20-2014
    Location
    Maryland, United States
    MS-Off Ver
    Excel 2003
    Posts
    5

    How to copy entire row based on criteria

    I cannot seem to figure out macros. I have been doing research on this for hours now, and I have tried using others post and modifying their code, but each time it comes back with an error. I have a spreadsheet that keeps track of all of the invoices I issue for my company, and than I track the invoices on whether they are 30 days, 60 days, or 90 days overdue. I have a column for 30 days, 60 days, and 90 days, I update my columns by placing a "Not Paid" in the column when the invoice passes the 30 day overdue mark. And so on and so forth for 60 days and 90 days overdue, but once the invoice is paid I insert Paid into the correct column and row. What I would like is to assign a macro that checks the first tab called "Invoice Information". And if for say under column H or "30 days" invoice 1 says not paid it copies that entire row and puts it on tab "30 Days". I also want the same to happen for column I for 60 days to go to tab "60 Days" and column J for 90 days to copy "90 days tab" Can someone please help me.

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: How to copy entire row based on criteria

    Sure. I've taught myself enough Visual Basic in the last few months to get this kind of thing done.
    And since I'm still mostly a VB noob, I can describe in a way average people might understand, mostly because of my lack of technical understanding of it. Kind of like knowing how to fix a car, without knowing how a car works.

    First, I'd recommend you post a sample of your work. If the data is confidential or classified, then desensitize. Scrub the stuff off of it you can't share. What I need are the actual rows, columns of what we'll move, measure, compare.

    You can attach a workbook by clicking on Go Advanced, then scrolling down to Manage Attachments, and then browsing to your file.

    Your first line of the macro is the name of the subroutine. Sub MoveStuff() works fine. Some macros have extra parameters in the (); I doubt this one needs it.

    Next you declare your variables, which you can name practically anything. Some programmers label them after their function, some name them something weird.
    There's a lot of types of variables, such as Range, Integer, Long, Double. It defines how the variable will be used. We'll use Range. They are defined with Dim meaning dimension. I'm not a programmer, so I don't understand a lot of why.

    Dim cells as Range

    We are declaring the word cells as a variable, and it's a range.
    Last edited by daffodil11; 03-20-2014 at 03:20 PM.
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Registered User
    Join Date
    09-28-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    53

    Re: How to copy entire row based on criteria

    This sounds like a job for pivot tables.

    One column called "Status" which could have values "Overdue 30", "Overdue 60", "Overdue 90", "Paid", and "Outstanding". Pick whatever values you want. Then just use a pivot table to report on the actual values.

  4. #4
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: How to copy entire row based on criteria

    We'll be doing something over and over, so we can use things like Do While or For which both can repeat.

    For example:

    Please Login or Register  to view this content.
    This will literally make A1 = 1, then 2, then 3 as it loops over and over each time adding 1 to itself. When x is no longer <10000 the loop will stop.

    For you, I'd go with For Each which does a similar kind of thing.

    Please Login or Register  to view this content.
    This looks at every cell in H2:H500 one at a time, checks if it is greater than 30, and if it is it copies the whole row to another sheet which I'm calling 30 Days Overdue, into the next empty row under column A. Then it repeats, over and over until it has checked all of those cells.


    Do While -> Loop and For -> Next are both really good ways to get your feet wet in basic coding. Once you can move data around a little bit, you can start to find more and more elaborate and complicated ways.
    Last edited by daffodil11; 03-20-2014 at 03:32 PM.

  5. #5
    Registered User
    Join Date
    03-20-2014
    Location
    Maryland, United States
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: How to copy entire row based on criteria

    Here's a copy of the workbook.
    Attached Files Attached Files

  6. #6
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: How to copy entire row based on criteria

    How about something like this?

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by daffodil11; 03-21-2014 at 08:42 AM. Reason: Attached Sample

  7. #7
    Registered User
    Join Date
    03-20-2014
    Location
    Maryland, United States
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: How to copy entire row based on criteria

    That works perfect! I couldn't thank you enough!

+ 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. Copy and Past Entire Row based off of Criteria into new Worksheet
    By KLiving in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-25-2013, 09:51 AM
  2. Copy entire row from Master sheet based on two criteria
    By melispol44 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-06-2013, 08:07 PM
  3. Copy entire row based on a criteria - using macro
    By scambug in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-23-2013, 02:37 AM
  4. How to copy an entire row from one sheet to another based on criteria
    By Mian USman in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-12-2013, 04:17 AM
  5. [SOLVED] Copy entire row to another sheet based on a criteria
    By Brig Siton in forum Excel General
    Replies: 3
    Last Post: 08-07-2006, 04:05 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