+ Reply to Thread
Results 1 to 23 of 23

copy and paste values based on a criteria

  1. #1
    Registered User
    Join Date
    04-15-2008
    Location
    Tamil Nadu, India.
    MS-Off Ver
    Microsoft Office 2016
    Posts
    582

    copy and paste values based on a criteria

    Dear Masters,

    I need a VBA code to do the following:

    I have a worksheet consist of some 17,000 records - from ColA:ColDZ. In Datasheet, I have all values. From this, based on some values in ColA all records should be copied into another sheet(s).

    I have attached a sample workbook in which I have explained the requirement.

    Please help me to find the solution.

    Thanks in advance.

    acsishere.
    Attached Files Attached Files
    Last edited by VBA Noob; 11-15-2008 at 12:17 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try this

    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    re: copy and paste values based on a criteria

    Try this simple code
    Please Login or Register  to view this content.
    It is different with the previous code in the fact that I copy per row and the previous code collects all rows (UNION) and copies this in two blocks. What I do not understand is why this is required?
    Please Login or Register  to view this content.
    Last edited by rwgrietveld; 11-12-2008 at 10:27 AM.
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  4. #4
    Registered User
    Join Date
    04-15-2008
    Location
    Tamil Nadu, India.
    MS-Off Ver
    Microsoft Office 2016
    Posts
    582

    Smile Dear Mr. RoyUK,

    Thanks a lot for your help. This is working very nicely.

    But, I need a small adjustment in it. I just wanted to paste the values in the other sheets only from 4th row onwards.

    Can you please help me, Sir.

    Thanks in advance.

    acsishere.
    Last edited by acsishere; 11-12-2008 at 10:24 AM.

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    The code that I provided copies from Row 3 which is the first line of data in your workbook datasheet.

    Edit: the other code does as well

  6. #6
    Registered User
    Join Date
    04-15-2008
    Location
    Tamil Nadu, India.
    MS-Off Ver
    Microsoft Office 2016
    Posts
    582

    Smile Dear Mr. RoyUK,

    Yes Sir,

    It is copying from row 3 onwards. But PASTING in other sheets from row 1 onwards. Here I need that it should be pasted from row 4 onwards.

    Please Sir,

    Thanks in advance,

    acsishere.

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    This will paste in row 4

    Please Login or Register  to view this content.
    Last edited by royUK; 11-12-2008 at 12:34 PM.

  8. #8
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    copy paste query

    see attached workbook.
    The code has been modified to paste in row 4 in destination sheets.
    modytrane
    Attached Files Attached Files

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Quote Originally Posted by modytrane View Post
    see attached workbook.
    The code has been modified to paste in row 4 in destination sheets.
    modytrane
    Am I missing something? The attachment contains my original code & will not paste to Row 4, the amended code, that I posted, does

  10. #10
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    copy paste quesry

    royUK,
    I had made small change to your code.

    Please Login or Register  to view this content.
    And it does work.
    The change was made on the two lines "case 1" and "case 2".
    I am still a novice when it comes to the VBA.
    So I was trying to understand your code and learn from it.
    I have benefited very much from these forums and in return if I could help in some way, I was trying to do just that.
    In case if you were busy, I was trying to help.

    It is your code and in no way was I trying to take any credit.
    Sorry, if you felt that way.

    modytrane.

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Quote Originally Posted by modytrane View Post
    royUK,
    I had made small change to your code.

    Please Login or Register  to view this content.
    And it does work.
    The change was made on the two lines "case 1" and "case 2".
    I am still a novice when it comes to the VBA.
    So I was trying to understand your code and learn from it.
    I have benefited very much from these forums and in return if I could help in some way, I was trying to do just that.
    In case if you were busy, I was trying to help.

    It is your code and in no way was I trying to take any credit.
    Sorry, if you felt that way.

    modytrane.
    No problem, I didn't see that. That's the best way to learn & it's good to see someone trying to understand the code.

  12. #12
    Registered User
    Join Date
    04-15-2008
    Location
    Tamil Nadu, India.
    MS-Off Ver
    Microsoft Office 2016
    Posts
    582

    Smile Dear Sirs,

    Thanks for your code and subsequent modifications.

    That's the spirit. Thanks again.

    Here, I need a bit more modification. i.e. the values must be copied in pastespecial mode paste:pastevalues.

    Because, my Outsh. sheets are already formatted and I don't want to disturb the formatted sheet. I just need to copy only the values.

    Please help.

    acsishere.

  13. #13
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    re:copy and paste values based on a criteria

    Added the starting from 4 and the pasteSpecial
    Please Login or Register  to view this content.

  14. #14
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try this

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    04-15-2008
    Location
    Tamil Nadu, India.
    MS-Off Ver
    Microsoft Office 2016
    Posts
    582

    Smile Dear Mr. RoyUK,

    Thanks for your reply.

    But when I run the code, again it copies entirely, not only the values.

    As I am to paste only the values and destination sheets are already formatted, I need your kind solution in this regard.

    Please Sir,

    Thanks in advance,
    acsishere.

  16. #16
    Registered User
    Join Date
    04-15-2008
    Location
    Tamil Nadu, India.
    MS-Off Ver
    Microsoft Office 2016
    Posts
    582

    Smile Dear Mr. RoyUK,

    I need your kind help accomplish the task successfully.

    Please Sir,

    Thanks in advance,
    acsishere.

  17. #17
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Does the last code not change to values?

    If not attach a small example workbook.

  18. #18
    Registered User
    Join Date
    04-15-2008
    Location
    Tamil Nadu, India.
    MS-Off Ver
    Microsoft Office 2016
    Posts
    582

    Smile Dear Mr. RoyUK,

    Dear Sir,

    Thanks for your reply.

    I am herewith attached the sample workbook with all the three codes.

    Thanks in advance.

    acsishere.
    Attached Files Attached Files

  19. #19
    Registered User
    Join Date
    04-15-2008
    Location
    Tamil Nadu, India.
    MS-Off Ver
    Microsoft Office 2016
    Posts
    582
    Dear Mr. RoyUK,

    Please help me to find the solution.

    Thanks in advance, acsishere.

  20. #20
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I can't see what the problem is. The examplee has no formatting in the other sheets, nor any formulas.

    When I add formulas the code replaces them with values.

  21. #21
    Registered User
    Join Date
    04-15-2008
    Location
    Tamil Nadu, India.
    MS-Off Ver
    Microsoft Office 2016
    Posts
    582

    Smile Dear Mr. RoyUK,

    Once again, this is acsishere.

    Good Evening Sir, as you said, I have once again attached the sample workbook, in which I have demonstrated the problem what I was facing.

    The code is the ultimate one, but it is to paste only the values instead of all formats.

    Please look into that, give me a solution Sir.

    Thanks in advance.

    acsishere.
    Attached Files Attached Files

  22. #22
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Hopefully this is what you want
    Please Login or Register  to view this content.

  23. #23
    Registered User
    Join Date
    04-15-2008
    Location
    Tamil Nadu, India.
    MS-Off Ver
    Microsoft Office 2016
    Posts
    582

    Thumbs up Dear Mr. RoyUK,

    That's it. And, You did it.

    Thanks a lot, lot, lot for your continuous support.

    Best wishes!

    acsishere.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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