+ Reply to Thread
Results 1 to 5 of 5

Copy and Paste using FOR loop and IF statement

  1. #1
    Forum Contributor
    Join Date
    06-30-2017
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2013
    Posts
    251

    Copy and Paste using FOR loop and IF statement

    As you can imagine by the title, I'm still new to VBA. I have a tab in an excel workbook, Frontier1. The idea is that I want to copy column C, but only where column C isn't blank and column F is greater than 0. Keep in mind I've replaced the data, but column F will normally be in decimal form, for what it's worth.

    I'm pasting to the Parse tab, where column J and K is the goal output.

    The code itself includes some other pieces where I'm finding the correct column but as you can see, the loop appears to be the main issue.

    Can someone please advise?

    Please Login or Register  to view this content.
    Any help appreciated!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,517

    Re: Copy and Paste using FOR loop and IF statement

    Please Login or Register  to view this content.
    Or
    Please Login or Register  to view this content.
    Last edited by jolivanes; 09-19-2019 at 12:25 PM.

  3. #3
    Forum Contributor
    Join Date
    06-30-2017
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2013
    Posts
    251

    Re: Copy and Paste using FOR loop and IF statement

    Thanks so much for this, very much appreciate the help. A couple questions...

    When I run the macro, I notice it pastes the strings "ISIN" and "Current" in the first row under "SYMBOL" and "WEIGHT" but in reality, I would need it to start with ISIN2 (since that's the first instance where Column C isn't blank and Column F >0).

    Also, can you please explain the IF statement being used?

    Lastly, I'm used to excel syntax and am wondering why you chose to move away from the initial piece of the loop in the original version.

    Please Login or Register  to view this content.
    Again, appreciate the help. Still learning...

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,517

    Re: Copy and Paste using FOR loop and IF statement

    Attached has the result I understood you were after. If not, let us know which Column you want the values in.

    Everybody has their own way of doing things. A few times I ran into problems with "IsEmpty" so I stay away from it. When I was Googling for a solution at that time several suggestions were to use what I use now and in this code.
    That is not written in stone though so use whatever works and is proper for the occasion.
    The first code checks if there is anything in the Cells in Column C and if there is and the Column 3 to the right has a Value > 0 then The first free cells in Columns J and K in Parse sheet will get these values.
    The 2nd code will check Column C only in the Cells that have something in it, not the empty cells.
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,517

    Re: Copy and Paste using FOR loop and IF statement

    I saw that you marked it solved. What was the problem? Was your attachment different from your original? Data started at a different row maybe?

+ 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. Loop to copy paste pivot table data changing the filter every time and copy it
    By PaulM100 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-22-2019, 06:58 AM
  2. [SOLVED] help refining this copy/paste IF AND statement macro (convert to a loop)?
    By Rerock in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-11-2013, 05:30 AM
  3. For Loop to Copy and Paste
    By djacobsen21 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-09-2013, 11:50 AM
  4. [SOLVED] Destination copy and paste (values only) for copy loop
    By mr_mango81 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-01-2013, 08:59 PM
  5. [SOLVED] Copy Paste Loop ends before copy/paste is finished
    By brgr4u in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-08-2013, 04:01 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. loop with a nested if statement to copy
    By Blizzak in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-25-2011, 04:23 PM

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