+ Reply to Thread
Results 1 to 8 of 8

Sort - copy rows to corresponding worksheet

  1. #1
    Registered User
    Join Date
    06-21-2010
    Location
    Richmond, Virginia
    MS-Off Ver
    Excel 2003
    Posts
    5

    Sort - copy rows to corresponding worksheet

    Hello,

    I have a spreadsheet that contains a seperate worksheet for each property. The first worksheet is where a list of invoices recieved will be entered with several bits of information. What I need is for all of the information on the first sheet to be copied to the correct worksheet based on the address which is in column A. Each week the information in the first sheet "invoices" will be cleared and new information will be entered that will be need to copied to the corresponding property worksheet. The code I have copies the information but I get an error when there is an address that does not have a worksheet with the same name. Is there a way to have it prompt the user to either correct the address if it was a typo or create a new worksheet? Thanks for any help.

    here's the code:

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Sort - copy rows to corresponding worksheet

    Hi kcj784

    You can try this code to see if a sheet exists for each property in Invoices
    Please Login or Register  to view this content.
    If you want the code to add Sheets for missing properties, uncomment the Sheets.Add.Name line. You could add a VBYesNo message box to give the user the option to add the Sheet or not.

    I'd call this procedure before you do a post.

    Let me know of issues.
    John
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    06-21-2010
    Location
    Richmond, Virginia
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Sort - copy rows to corresponding worksheet

    Thanks a bunch John! That works great. Now my program runs "test for sheets" and if no new sheets are required then the sort subroutine runs. Thanks for your help.

    Maybe this is a question for another post but is there a way to alter the code posted about so that after it is determined that a row is to be copied to a worksheet, there is a check to see if the row being copied already appears in the worksheet? Possibly something that checks the data in columns B, C, D and if they're all identical to a row already in the worksheet then a message pops up detailing the duplication?

    kcj
    KJ

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Sort - copy rows to corresponding worksheet

    Hi KJ

    What you ask could be done but it would involve a LOT of looping. I'm curious what you're concern is. Is it that an Invoice will get double posted or are you concerned that an Invoice will get double entered.

    The double posting is fairly simple; just flag the line as posted and have the procedure to check for that flag the next time you post.

    Double entering is another issue that accounting systems control internally (invoice number checks, etc). Something like that could PROBABLY be developed in Excel but I'd suggest just being careful.

    John

  5. #5
    Registered User
    Join Date
    06-21-2010
    Location
    Richmond, Virginia
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Sort - copy rows to corresponding worksheet

    Hey John,

    I guess my first concern is double posting. I wouldn't whoever was in the spreadsheet to accidentally run the macro twice before the data in the first sheet had been cleared, thus causing each sheet to have double record of an invoice. I think to fix this I could have the "invoice" sheet cleared after all of the data has been copied. This first sheet will be cleared, with new data entered and copied weekly so I guess that would work.

    A secondary concern was that sometimes our vendors will send us a copy of an invoice we've already recieved and we pay it again not realizing that it's a duplicate. We often receive so many invoices that it's hard to notice duplicates. I agree, such a detailed, column by column check would probably end up being more trouble than it's worth. I agree with the part about being careful lol. I will just start recording the invoice number and maybe a check of just that column would be more feasible. Would that be something I could implement easily with vlookup? I'm guess that would go right before this part of my code:

    Please Login or Register  to view this content.
    KJ

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Sort - copy rows to corresponding worksheet

    Hi KJ

    I'd do some research on Google, something like "Find Duplicates In a Column Excel". You'll get plenty of hits.

    Let me know how I can help.

    John

  7. #7
    Registered User
    Join Date
    06-21-2010
    Location
    Richmond, Virginia
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Sort - copy rows to corresponding worksheet

    Thanks John. One question about the code you provided, is there an easy way to apply a format to each sheet created by the sheets.add.name line? Maybe if "sheet2" has the desired headings, format, conditional format applied to a certain column, could I just have each new sheet follow that format?

    KJ

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Sort - copy rows to corresponding worksheet

    Hi KJ

    I'd probably create a named range "Headings" then copy that range to the new sheet. I should think you could also copy the formats (only) from any given sheet to the new sheet.

    Play with it; if you need help, let me know.

    John

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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