+ Reply to Thread
Results 1 to 10 of 10

Copy & Paste Values Based on IF Statement

  1. #1
    Registered User
    Join Date
    07-05-2012
    Location
    New Jersey, US
    MS-Off Ver
    Excel 2010
    Posts
    57

    Copy & Paste Values Based on IF Statement

    Hello,

    I need a fairly simple macro made, but am getting stuck up. I've attached the file for reference.

    First, on the 'Post ID' tab:
    - I need to copy and paste all values that are not 0 from columns B, C, D into column A
    - The inputs in columns B, C, D are formulas, which is why i need to paste as values
    - For the current attached example, it should return 540 post IDs
    - I'm leaving a running formula in columns B, C, D so that I don't have to drag down any further and the post IDs will automatically update on this tab as we get the data

    Second, on the 'Combined' tab:
    - I want to copy and paste as values all the post IDs from column A in the tab 'Post ID' (row 2 as far down as the post list goes based on the above statement)
    - This will re-paste the full updated list from the tab 'Post ID' into the 'Combined' tab starting in cell A4

    I hope this gives enough detail for what I need. In general, I just need the macro to give me the full list of post IDs for me to run vlookups off of. I've dragged down the formulas to retrieve the post IDs in columns B, C, D as far down as I anticipate (which is why you see 0's going down to row 5000 on the 'Post ID' tab). But there is the small chance I would need to drag it down further.

    Thanks in advance!
    Attached Files Attached Files

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Copy & Paste Values Based on IF Statement

    for the Post ID tab, you say you want BCD into A if the value is not 0.... do you mean when column C is not 0 or B or D? (or when none of the columns are 0),
    and do you want columns BCD combined into A? if so, any separator between them? (I also don't understand how you get to 540 since there are only 527 rows with numbers in them, and many of those are 0 across all columns...

    EDIT I believe I just got it... You want all the values from B C or D that are not 0 copied over to column A individually?
    Last edited by Arkadi; 05-25-2017 at 10:33 AM.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    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: Copy & Paste Values Based on IF Statement

    Hi Arkadi

    I struggled to understand that too. In the end I realised the 540 is
    245 non zeros in column B, +
    77 non zeros in column C +
    218 non zeros in column D.
    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.

  4. #4
    Registered User
    Join Date
    07-05-2012
    Location
    New Jersey, US
    MS-Off Ver
    Excel 2010
    Posts
    57

    Re: Copy & Paste Values Based on IF Statement

    Sorry for the confusion, that is correct. I want to select all rows in column B that are not 0, copy and paste as values over to column A, then do the same for column C & D. They do not need a separator in column A, just the full list that pulls all post ID's that are not 0.

    So it would copy rows 2 through 246 in column B (since the 0's start after that) and paste as values in A2. Then it would copy rows 2 through 78 in column C, and paste as values starting in A247 (since that is where the last copy and pasted values from column B ended. Then it would continue this process for the data in column D.

    After the complete post ID list (inclusive of all post IDs from columns B, C, D) is in column A, that will then be transported over to the other tab as noted in my initial post.

    Thanks again!

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Copy & Paste Values Based on IF Statement

    Lets see if this works for you?

    Please Login or Register  to view this content.
    Last edited by Arkadi; 05-25-2017 at 11:11 AM. Reason: Small correction to data-clearing code.

  6. #6
    Registered User
    Join Date
    07-05-2012
    Location
    New Jersey, US
    MS-Off Ver
    Excel 2010
    Posts
    57

    Re: Copy & Paste Values Based on IF Statement

    One other thing I forgot to mention. Could the macro replace whatever pre-existing data is in the columns when pasting as values? Since it will be a running total of all the post IDs, it should always be larger every time we run the macro with the updated list.

  7. #7
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Copy & Paste Values Based on IF Statement

    Lol montoro, yes I put in some code that clears the old data first (that's the optional section), then saw your addition

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Copy & Paste Values Based on IF Statement

    OOOPS! I had made a small mistake... it didn't clear old data properly... should be fixed now, I edited my post.

  9. #9
    Registered User
    Join Date
    07-05-2012
    Location
    New Jersey, US
    MS-Off Ver
    Excel 2010
    Posts
    57

    Re: Copy & Paste Values Based on IF Statement

    Works like a charm! Thank you so much!

    Was just about to mention the first post ID being duplicated, but it looks like the edit fixed that.

  10. #10
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Copy & Paste Values Based on IF Statement

    You are very welcome Glad it seems to do what you want.
    Once you are sure it works well, please remember to mark the thread as solved? Thanks!

+ 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] Copy and paste to one row based on matching values
    By mhf89 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 03-14-2017, 10:03 PM
  2. Copy paste Values based on criteria
    By toci in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 04-15-2016, 08:29 AM
  3. [SOLVED] Copy paste values to another workbook based on multiple cell values
    By Bazinga in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-23-2014, 12:41 PM
  4. [SOLVED] Copy and paste based on two values
    By WVSpelunker in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2012, 01:52 PM
  5. [SOLVED] Copy and Paste based on If statement
    By ATLGator in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-27-2012, 08:57 AM
  6. Copy and Paste values based on another cell
    By clc3 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-14-2012, 05:15 PM
  7. copy and paste values based on a criteria
    By acsishere in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 11-15-2008, 11:35 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