+ Reply to Thread
Results 1 to 13 of 13

Transfer Copy/paste based on criteria

  1. #1
    Forum Contributor
    Join Date
    07-12-2005
    Posts
    143

    Transfer Copy/paste based on criteria

    Hi all,

    Way too long since i've been on this site. Got a question in VBA. Could someone help please with the following scenario:

    6 worksheets ("Monday" ,"Tuesday" etc)
    1 Worksheet (call it Main)

    In the Main sheet let's say there are 3 column headings - Date, Inv No, Amount

    I want to copy from the Main sheet to the appropriate day e.g if the dates in the main are13/01/10 and 14/01/10 then all the info pertaining to 13/01/10 should go to the Wednesday worksheet.

    Sorry if i didn't explain myself properly - its getting late here! As usual many thanks to all you Excel guys and gals who have helped in the past.

    Regards,

    Chris

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Transfer Copy/paste based on criteria

    Hi,

    One way would be to add a fourth helper column to the main sheet and add the function:
    Please Login or Register  to view this content.
    and copy this down your data. This will return 1,2,3 etc. for Sunday, Monday, Tuesday

    Now all you need do is construct a simple VBA looping macro which filters your main sheet data for each day, and then copies and pastes the filtered rows to the appropriate sheet.

    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    07-12-2005
    Posts
    143

    Re: Transfer Copy/paste based on criteria

    Thanks Richard,

    I have done similar to the first part - it was the VBA looping macro thing that i'm a complete novice at!

    regards

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Transfer Copy/paste based on criteria

    Hi,

    Try the attached. Hopefully it gives you the general idea. Click the blue button to run the macro.

    Regards
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    07-12-2005
    Posts
    143

    Re: Transfer Copy/paste based on criteria

    Thanks Richard - that was really handy. How can i stop it that if i enter different data afterwards the macro will append to the correct day rather than wipe over the previous data?
    i.e run the macro once then erase that info, reenter and run the macro again.

    Regards

    Chris

  6. #6
    Forum Contributor
    Join Date
    07-12-2005
    Posts
    143

    Re: Transfer Copy/paste based on criteria

    Richard,

    Further to the above - could you please explain a little how the macro in this case works e.g what "Cells(2, 1)" relates to? I tried changing things a little to experiment and keep getting run time errors.

    Cheers again!

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Transfer Copy/paste based on criteria

    Hi Chris,

    The line in question refers to the range name "crit". If you look at this range in the workbook you'll see it refers to H1:H2.

    So the .Cells(2,1) simply refers to the cell in the 2nd row 1st column of this range, i.e. H2. The .Cells instruction is quite useful since it enables you to address a particular cell relative to another. So Range("D4").Cells(3,3) would refer to F6, and Range("D4").Cells(0,0) would refer to C3, and Range("D4").Cells(-2,3) would refer to F1.

    In your macro we are putting the loop counter x in the second cell of the criteria range i.e. cell H2, and x in this case loops from 1 to 7 which represents the day of the week that we've identified in column D.

    HTH

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Transfer Copy/paste based on criteria

    Hi Chris,

    I see I forgot to answer the second part of the question.
    At the moment the macro uses Excel's standard Data filtering process. This means that the output range of the date being filtered is automatically cleared as part of the filtering process. In this case each day's tab is a separate output range hence they all get refreshed.

    In order to add new records to each day then the simplest way would be to have a single dedicated output range to which each day's data is first filtered. Then have the macro copy this data below any previous data on the relevant day's tab.

    If you want me to revise the macro then let me know.

    Regards

  9. #9
    Forum Contributor
    Join Date
    07-12-2005
    Posts
    143

    Re: Transfer Copy/paste based on criteria

    Hi Richard,


    To be honest that would be great - I have to build something relatively sharpish and anything that speeds it along would be a lifesaver!

    Cheers,

    Chris

  10. #10
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Transfer Copy/paste based on criteria

    Hi,

    See the revised workbook attached.

    I've added an extra button which will erase all the data on all the seven daily sheets if that is required.

    Regards
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    07-12-2005
    Posts
    143

    Re: Transfer Copy/paste based on criteria

    HI Richard,

    Just had a look at the adapted code this morning and it works great. I'm just going to adapt it to my worksheet and i'll keep you posted later today.

    br,

    chris

  12. #12
    Forum Contributor
    Join Date
    07-12-2005
    Posts
    143

    Re: Transfer Copy/paste based on criteria

    Hi Richard thanks for all your help so far. Please could you help with one more thing? I'm having trouble relating the code to my worksheet.

    If you see the attached (i've removed as much references and code as possible to minimise its size) and look at worksheet ACTISHEET. This is to be the front office tool for sales staff to dissect sales on. The summary info is at cells A502:I502. When the ticket is processed the range A478:I500 is sent to somewhere then the line A502:I502 needs to go to the appropriate day Monday to Saturday.

    I was thinking about sending the summary to a single page for the whole week but I wanted to try and keep everything as similar to the original as possible.

    There is likely to be several entry tickets for one page in case a ticket is held in 'limbo' but in general if the code works for line A502:I502 then i can duplicate for A528:I528 if necessary.

    Sorry for being a bother but when it comes to arrays and looping i'm a bit of a dufuss!

    Regards,

    Chris

  13. #13
    Registered User
    Join Date
    02-06-2010
    Location
    Devon,England
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Transfer Copy/paste based on criteria

    Hello there. Have you found a solution to yuour problem yet Chris? I have somthing similar that i'm trying to sort out but not like your attached. Let me know please.

+ 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