+ Reply to Thread
Results 1 to 12 of 12

Copy paste columns if criteria is met

  1. #1
    Registered User
    Join Date
    08-23-2014
    Location
    Miami, USA
    MS-Off Ver
    365
    Posts
    69

    Exclamation Copy paste columns if criteria is met

    I'm having problems trying to get my code to work and I need some improvements to it as well.

    I need to copy and paste all the values in the Source worksheet ("Totals") to the destination worksheet ("Monthly Overall"), but only if the column headers (which are date values) in the source worksheet ("Totals") match the destination worksheet ("Monthly Overall") column headers (which are dates as well). I would also like it, if it could verify, before copying, that the order of the list of names match in both worksheets, if it doesn't match then don't copy.

    Another issue is that I have three sets of tables within the Source worksheet that need to be taken into account, so I'm not sure what's the best way to go through all the data ranges and copy them to the destination worksheet if the above criteria (s) are met.

    My initial approach was to look at the column dates and if they match then copy and paste the column to the destination worksheet that matches that date value.
    Here is what I have so far, please help, I'm new to VBA and this code is not working for me:

    Please Login or Register  to view this content.
    FYI: The reason why I need this is because the source data will be changing and I need to keep a record of that data.
    Attached Files Attached Files
    Last edited by sandy1977; 01-18-2016 at 09:24 AM.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Copy paste columns if criteria is met

    Since you are using merged cells in your formatting, I suggest you create your archives like this.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-23-2014
    Location
    Miami, USA
    MS-Off Ver
    365
    Posts
    69

    Re: Copy paste columns if criteria is met

    Thank you for your response but unfortunately that will not work for me. I have updated the file, unmerging the rows with the names and I have updated the "destination worksheet ("Monthly Overall"), to probably make things easier. Hopefully you can still help me. If the order of the names canīt be checked before copying and pasting the data, I can make it work if the code transfers the data to the column header dates that match the Source column header date.

    Thanks
    Last edited by sandy1977; 01-17-2016 at 04:13 PM.

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Copy paste columns if criteria is met

    This should work but it don't. It works to a point then begins returning 'Nothing' for the fn variable. I have spent more time on it than I wanted to, trying to figure out your worksheet idiosyncrasies and have not solved the problem. Maybe somebody smarter than me can figure out how to get the correct columns to copy without using the find method. This is what I was working with, in case somebody else wants to try and debug it.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-23-2014
    Location
    Miami, USA
    MS-Off Ver
    365
    Posts
    69

    Re: Copy paste columns if criteria is met

    Thank you for trying

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,517

    Re: Copy paste columns if criteria is met

    Try this.
    Please Login or Register  to view this content.
    Note : Dates in Week 10 & 11 are identical in your file.

  7. #7
    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: Copy paste columns if criteria is met

    @Jindon

    Good catch...didn't notice that...
    Note : Dates in Week 10 & 11 are identical in your file.
    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.

  8. #8
    Registered User
    Join Date
    08-23-2014
    Location
    Miami, USA
    MS-Off Ver
    365
    Posts
    69

    Re: Copy paste columns if criteria is met

    @jindon. Thank you, its works, if it's not too much to ask, could you explain to me each line of code.

    Thanks

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,517

    Re: Copy paste columns if criteria is met

    Quote Originally Posted by jaslake View Post
    @Jindon

    Good catch...didn't notice that...
    Yes and thanks for the rep.

    Quote Originally Posted by sandy1977
    @jindon. Thank you, its works, if it's not too much to ask, could you explain to me each line of code.
    1) Detect cells that have numbers(dates in this case) in Row 4 in "Totals" sheet,
    2) Ref each currentregion in 1) and get matched first date in "monthly overall" row 4.
    3) If matched date found, copy required range to the column that matched.

  10. #10
    Registered User
    Join Date
    08-23-2014
    Location
    Miami, USA
    MS-Off Ver
    365
    Posts
    69

    Re: Copy paste columns if criteria is met

    When I run the code in my actual spreadsheet (see picture) its giving an error at this line:

    Set myAreas = Sheets("Totals").Rows(7).SpecialCells(2, 1).Areas <-------'my dates in this spreadsheet start at row 7

    "Its says No cells were found"

    Could it be because I have formulas in those cells?

    1-17-2016 8-16-16 PM.jpg

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,517

    Re: Copy paste columns if criteria is met

    If you are talking about the file other than the one you uploaded, no idea.

  12. #12
    Registered User
    Join Date
    08-23-2014
    Location
    Miami, USA
    MS-Off Ver
    365
    Posts
    69

    Re: Copy paste columns if criteria is met

    Ok, thank you for all your help, you've been very helpful.

+ 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 paste data based on criteria from row and columns
    By rz6657 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-04-2015, 03:33 PM
  2. Copy multiple columns and paste into one column, based on row criteria
    By Miki1989 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-17-2015, 09:59 AM
  3. [SOLVED] Copy and paste columns to another sheet based on a criteria
    By saya_26 in forum Excel General
    Replies: 17
    Last Post: 02-24-2014, 12:23 PM
  4. Replies: 1
    Last Post: 09-03-2013, 07:41 PM
  5. [SOLVED] Copy/Paste multiple columns as values based on another columns criteria
    By Dgp2012 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-28-2013, 06:50 AM
  6. Copy and Paste and Delete Columns Based on Criteria
    By datalogger in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-21-2010, 01:07 PM
  7. 2 Macro's: only vertical copy/paste action and copy-paste 14 columns to the right.
    By vdongen in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-08-2010, 10:34 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