+ Reply to Thread
Results 1 to 10 of 10

Copy/Paste Values from Variable Range to Corresponding Variable Range

  1. #1
    Registered User
    Join Date
    05-12-2012
    Location
    Miami, Florida
    MS-Off Ver
    Excel 2007
    Posts
    8

    Copy/Paste Values from Variable Range to Corresponding Variable Range

    Hello. I'm new to this forum, though I have used it on many occasions to solve some of my VBA troubles (as I'm a VBA novice and have tried to learn from those far more sophisticated than me). For the problem at hand, however, I haven't been able to piece together a solution after mining many message boards. I've seen many similar problems, but nothing yet that satisfied all of the conditions of my problem.

    The problem: I'm trying to write a macro that will copy values from a named range that meet a condition where the range is in a column containing many rows on the "Export Draws" tab (copy range), and paste those values to a named range on another worksheet where the range is in a column containing the same number of rows on the "Projections" tab (paste range). I need to do this up to 39 times, although my ideal solution will copy all "copy ranges" to the corresponding "paste ranges".

    Additionally, if the copy condition is not met (also each named range [a one-cell trigger] on the Export Draws tab). The condition is met if trigger is = 0 (or if = 1, then next).

    I've attached a worksheet to (hopefully) illustrate better what I'm talking about.

    Though I know I need to set variables, and run a loop I am completely stumped where to begin, so haven't even begun to write any code.

    Any help you all can provide will be enormously helpful - Thank you in advance.

    Attachment 155431
    Attached Files Attached Files

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy/Paste Values from Variable Range to Corresponding Variable Range

    Your sample sheet doesn't have a single named range it it. What happened to them?

    They aren't really necessary. You could logically have the macro simply copy B19:BXXXX (where XXXX is the bottom of the data in that columm) to the other sheet in the column where Export-row20 = Projections-Row6.

    It would do that for every value of 1 in Export-Row7.
    Last edited by JBeaucaire; 05-12-2012 at 11:13 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    05-12-2012
    Location
    Miami, Florida
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Copy/Paste Values from Variable Range to Corresponding Variable Range

    Jbeaucaire - you are correct that the sample doesn't include named ranges (it's just a sample copy from the sheets that I'm working with, and didn't want to go through the naking process again). In any case, I am using named ranges so that - should I need to add rows, I wont have to revise the macro once written. This may be an inartful solution.

    I'm curious if you have any suggestions to begin writing the code - since this is where I am sincerely stumped.

    Thanks.

  4. #4
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Copy/Paste Values from Variable Range to Corresponding Variable Range

    (1) What is the name & address of the named range?
    (2) Under what conditions do you want to copy values?
    (3) Where do you want these values copied?

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy/Paste Values from Variable Range to Corresponding Variable Range

    Unanswered from post #2:
    Quote Originally Posted by jbeaucaire
    They aren't really necessary. You could logically have the macro simply copy B19:BXXXX (where XXXX is the bottom of the data in that columm) to the other sheet in the column where Export-row20 = Projections-Row6.

    It would do that for every value of 1 in Export-Row7.

    What do you think?

  6. #6
    Registered User
    Join Date
    05-12-2012
    Location
    Miami, Florida
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Copy/Paste Values from Variable Range to Corresponding Variable Range

    Quote Originally Posted by JBeaucaire View Post
    Unanswered from post #2:



    What do you think?
    Yes that sounds correct - named ranges aren't necessary and the references look correct too.

  7. #7
    Registered User
    Join Date
    05-12-2012
    Location
    Miami, Florida
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Copy/Paste Values from Variable Range to Corresponding Variable Range

    I am re-posting the sample worksheet given the questions about named ranges. Thanks everyone for looking at this.
    Attached Files Attached Files

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy/Paste Values from Variable Range to Corresponding Variable Range

    This macro will work without any of the named ranges needing to be present. It uses the key text strings in column A to spot things like:

    Row with flags to check (only transfer columns with a numeric value other than 1)
    Row with dates
    Top row of your data to transfer
    Bottom of the data to transfer

    Then it spots the row with dates on the Projections sheet

    Then it transfers the columns from Export Draws to Projections matching on those dates.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    05-12-2012
    Location
    Miami, Florida
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Copy/Paste Values from Variable Range to Corresponding Variable Range

    Thank you Jbeaucaire. Truly wonderful solution! Thank you very much! I had been thinking of named ranges as the solution, but you proved not necessary. I tested in the sample and original workbooks, and so far it's working perfectly. Learned a lot as well. I'm still unclear about the syntax you used, but as I said - VBA novice.

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy/Paste Values from Variable Range to Corresponding Variable Range

    I tried to comment as much as I could so it was clear WHAT each line of code accomplishes, that should aid as you try to decipher HOW it accomplihed that.

    If that takes care of your need, please select Thread Tools from menu above and set this topic to SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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