+ Reply to Thread
Results 1 to 14 of 14

Copy & paste with specific condition to destination sheet

  1. #1
    Forum Contributor
    Join Date
    06-01-2015
    Location
    Chennai,India
    MS-Off Ver
    Microsoft Office 2021
    Posts
    146

    Copy & paste with specific condition to destination sheet

    Hi all,

    I have been looking for the below requirement for past 5 hours but I couldn't find it. Below are my requirement.

    1. I want to copy the data (Column A to E) from the Sheet "Raw" to "Summary" but I want to copy paste the details based on the numbers provided in the table from Column I to K.

    Eg. As per the table, if the country is IN and the entity code is lesser than 5000 then i should copy the first single entries to the "Summary" Sheet.
    Note: The details provided in the table (Column I to K) is constant, it will not change.


    2. Here my challenges starts, I should copy paste the line items as per the count provided in the table.

    Eg. I should copy and paste only 2 EUR line items which has the entity code between 5000 to 20000 but my data (Column A to E) may or may not have more than 2 EUR line items but I should copy and paste only the first line 2 items in the summary sheet since that is my requirement.

    3. My second challenge, some times those country details will not be available in the data (Column A to E) so during those scenarios i should skip that case and move on to the next country.

    I have pasted my desire output in the summary sheet. Please assist me to resolve it.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy & paste with specific condition to destination sheet

    Try attached file: Can't post code. System thinks it contains HTML
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    06-01-2015
    Location
    Chennai,India
    MS-Off Ver
    Microsoft Office 2021
    Posts
    146

    Re: Copy & paste with specific condition to destination sheet

    Hi Minicab,

    Thanks a lot. It is working perfect. but one condition is not working.

    I should copy paste the data as per the count provided in the no. of entries in Column K.

    Eg. I should copy and paste only one line item for the country IN since it is mentioned as 1 in the No. of the entries column in Column K and same goes for EUR wherein I should paste 2 entries and for NAM I should paste 5 entries.

    also Eg. NAM has 5 entries should be pasted to the summary but in some scenario i may have lesser than 5 during those scenarios I should paste whatever having lesser than 5.

  4. #4
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Copy & paste with specific condition to destination sheet

    Hi Revathi,

    This is an alternative method using Advanced Filter ... You just need to slightly change the criteria table as per the attached file which can you change without altering the VBA code itself in case you need to in the future

    Please Login or Register  to view this content.
    Attached Files Attached Files
    If I was able to help, you can thank me by clicking the * Add Reputation under my user name

  5. #5
    Forum Contributor
    Join Date
    06-01-2015
    Location
    Chennai,India
    MS-Off Ver
    Microsoft Office 2021
    Posts
    146

    Re: Copy & paste with specific condition to destination sheet

    Hi Nankw83,

    Thank you for your valuable time but i am not getting my desired output as per the changes done in your attached file.

    Eg. while copy the EUR details you have mentioned it to copy Range from (A1 to E3) but i need to copy only the visible cells after filter.. Those visible cells may appear at row 17 or 18 or 21.

  6. #6
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Copy & paste with specific condition to destination sheet

    Have you run the code in my attached file ? The range A3:E3 is where the data will be copied to (destination)

  7. #7
    Forum Contributor
    Join Date
    06-01-2015
    Location
    Chennai,India
    MS-Off Ver
    Microsoft Office 2021
    Posts
    146

    Re: Copy & paste with specific condition to destination sheet

    Hi Nankw83,

    Thanks a ton.. it works greatly.. but please let me know the purpose of Column 6.clear contents.

  8. #8
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Copy & paste with specific condition to destination sheet

    Glad to help & thanks for the added Rep.

    I am placing a formula in column 6 =COUNTIF($B1:B$1,B1) to count the occurrences of each country that is used in the Advanced Filter & once the data is generated in the destination sheet, I am clearing the formula in columns 6 ... If you step through the code line by line using F8 key, you'll see what I mean

  9. #9
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy & paste with specific condition to destination sheet

    For thoroughness, I completed the requirements. But Nankw83 solution is much more efficient

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    06-01-2015
    Location
    Chennai,India
    MS-Off Ver
    Microsoft Office 2021
    Posts
    146

    Re: Copy & paste with specific condition to destination sheet

    Hi NankW83,

    My second condition is not working. Please refer the "list" sheet wherein it should copy and paste the details in summary based on the country and Weight.

    1. Copy the first visible entry of IN which is lesser than 5000 and should be pasted in the Summary sheet.
    2. Copy the first 2 visible entries of IN which is greater than equal to 5000 and lesser than equal to 20000 and should be pasted in the summary sheet.
    3. copy the first 5 visible entries of IN which is greater than 20000 and should be pasted in summary sheet.

    The above steps has to be followed for all the 12 scenarios in the "List" sheet.

    As per your previous code it is just copy and pasting the details based on country but not validating the weight.

    Please correct me if I am wrong.

    Thanks.
    Attached Files Attached Files
    Last edited by Revathi kannan; 10-19-2020 at 03:36 PM.

  11. #11
    Forum Contributor
    Join Date
    06-01-2015
    Location
    Chennai,India
    MS-Off Ver
    Microsoft Office 2021
    Posts
    146

    Re: Copy & paste with specific condition to destination sheet

    Hi Maniacb,

    will try it out your method as well. .thank you so much for your time.

  12. #12
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Copy & paste with specific condition to destination sheet

    Hi Revathi,

    Your file structure in post #10 is different than your sample file in your original post & that's why the provided code in post #4 is not working properly. In addition, the code is using Advanced Filter where the destination sheet fields should exist in your source data - "Total" column is not. Lastly, the way you set up your filter list in sheet "List" is not correct. I suggest that you read a little about Advanced Filter HERE to understand how to set up your filter (this doesn't require VBA knowledge) & once you do, you can alter my code above to make it suite your revised file

  13. #13
    Forum Contributor
    Join Date
    06-01-2015
    Location
    Chennai,India
    MS-Off Ver
    Microsoft Office 2021
    Posts
    146

    Re: Copy & paste with specific condition to destination sheet

    Hi Nankw83,

    Sorry for the confusion. i have gone thru the article but even i am not able to find my answer. Please assist.

    1. I will go with as per my Old sample file wherein i have a condition that i need copy paste the first 2 visible rows after filtering the EUR country where the weight between >=5000 to <=20000. Only this condition is not working. I have highlighted the result in the summary sheet.
    Attached Files Attached Files

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

    Re: Copy & paste with specific condition to destination sheet

    Different method
    Please Login or Register  to view this content.
    Attached Files Attached Files

+ 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. VBA to Copy Paste and Format Destination sheet
    By FredFitzgerald in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-06-2019, 09:50 AM
  2. Copy from static destination & paste to dynamic destination
    By Marbleking in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-31-2015, 09:31 AM
  3. [SOLVED] VBA code, cut and paste entire row into new sheet per specific condition in cell
    By Tapyr in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-07-2015, 08:53 AM
  4. Auto copy specific data from sheet to antoher sheet under few condition
    By Shermaine2010 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-17-2014, 04:47 AM
  5. How to copy paste specific cells is a condition is met
    By PriyankaV in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-13-2014, 10:27 PM
  6. Copy specific row data with condition and paste into new workbook
    By tdugga in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-23-2013, 06:32 AM
  7. Copy and Paste Special Values Macro ignoring cells with specific condition
    By chendriks47 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-06-2011, 03:01 AM

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