+ Reply to Thread
Results 1 to 9 of 9

IF Date THEN Loop Copy Cells

  1. #1
    Registered User
    Join Date
    05-26-2019
    Location
    UK
    MS-Off Ver
    2016
    Posts
    50

    IF Date THEN Loop Copy Cells

    Hi, I'm looking to copy over specific cells from one sheet to another, if the first cell (date) in a given row is a date which is equal to or higher than the date provided in cell C1. Cells to copy are in columns A, B, C, E & G and they should be copied over to A, B, C, F & G, accordingly. Please note that the data in sheet1 starts on row 3 and in sheet2 on row 2.

    Here's some sample code I've been playing around with to get this to work, as well as to perhaps help illustrate a little bit more what I'm trying to achieve.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: IF Date THEN Loop Copy Cells

    Here are some suggestions

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-26-2019
    Location
    UK
    MS-Off Ver
    2016
    Posts
    50

    Re: IF Date THEN Loop Copy Cells

    Thanks, appreciate the quick response.
    How about the copying of specific cells and pasting under specific columns? Not sure how to go about that while at the same time using things like e.g. NextRow or LastRow

    Thank you.

  4. #4
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: IF Date THEN Loop Copy Cells

    Can you clarify what you mean by that?

  5. #5
    Registered User
    Join Date
    05-26-2019
    Location
    UK
    MS-Off Ver
    2016
    Posts
    50

    Re: IF Date THEN Loop Copy Cells

    Sure. As I mentioned in the first post, I only want to copy cells A, B, C, E & G from sheet1 and paste them over to sheet2 under A, B, C, F & G, accordingly. Thanks!

  6. #6
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: IF Date THEN Loop Copy Cells

    Okay, got it. Tidied the code up a bit more as well.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    05-26-2019
    Location
    UK
    MS-Off Ver
    2016
    Posts
    50

    Re: IF Date THEN Loop Copy Cells

    This is great, thank you. Only thing is, for some reason it's ignoring the header on the 2nd sheet and just starts pasting data right over it. What would be the best way to start pasting on row 2?

  8. #8
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: IF Date THEN Loop Copy Cells

    Add a line to assign NextRow the value 1 before looping through the range rg (it is defaulting too 0, so as it is incremented by 1 for each valid row, it starts at row 1).

  9. #9
    Registered User
    Join Date
    05-26-2019
    Location
    UK
    MS-Off Ver
    2016
    Posts
    50

    Re: IF Date THEN Loop Copy Cells

    Ah, you're right. Forgot to set it... Sorry about that. Thanks again!

+ 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] Loop through copy and paste cells VBA
    By Ollie7957 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-13-2019, 11:07 AM
  2. VBA > Loop Help > Copy, Paste, Format Date - Is there a better way to do this?
    By MontgomeryBrea in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-20-2019, 09:45 PM
  3. [SOLVED] loop to copy blank cells between 2 filled cells
    By Spyderwoman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2016, 12:44 AM
  4. [SOLVED] Copy Cells to available blank cells in rows below loop
    By lee1000d in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-17-2015, 02:21 PM
  5. Copy, Paste loop based on today's Date
    By oscarmiike in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-22-2014, 09:05 PM
  6. [SOLVED] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  7. [SOLVED] VBA Copy certain cells then loop
    By zhb12810 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-13-2012, 03:53 PM

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