+ Reply to Thread
Results 1 to 21 of 21

VBA code for extracting data from a list as per given criteria

  1. #1
    Forum Contributor daksh1981's Avatar
    Join Date
    04-15-2009
    Location
    India
    MS-Off Ver
    2003 & 2007
    Posts
    110

    Thumbs up VBA code for extracting data from a list as per given criteria

    Hi I need a help on a VBA code. Suppose I have a list of data in which I want to retrieve or extract specific row from the list as per operator name & relative comments (Done or Not Done) from the given list as per the operator name, now what I want that my VBA code should be able to get the operator name & the relative comment data from the list according to the operator name in a new sheet. My data keeps changing so I need a code which can work on any size of the data. I need to retrieve only operator name & Comment column in a new sheet to run my Pivot table.
    My Excel data is something like in the attachment & the result I want through VBA Code.
    Attached Files Attached Files
    Last edited by daksh1981; 04-29-2009 at 03:39 AM. Reason: Not formated

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA code for extracting data from a list as per given criteria

    Can't you just copy columns A & C in the first worksheet to A & B in the 2nd?

  3. #3
    Forum Contributor daksh1981's Avatar
    Join Date
    04-15-2009
    Location
    India
    MS-Off Ver
    2003 & 2007
    Posts
    110

    Re: VBA code for extracting data from a list as per given criteria

    Thanks for replying . The attached excel file is only a example I have huge data with multiple columns & rows. Using macro will definitely reduce time which I want. I need a VBA code for this. Which will produce the desired result as mentioned in the sheet.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA code for extracting data from a list as per given criteria

    There's only one attachment and that's in your 1st post.

    And all you seem to be doing is deleting/moving columns.

    I don't see any criteria happening or the data being manipulated in any way.

  5. #5
    Forum Contributor daksh1981's Avatar
    Join Date
    04-15-2009
    Location
    India
    MS-Off Ver
    2003 & 2007
    Posts
    110

    Re: VBA code for extracting data from a list as per given criteria

    Hi friend, the attached sheet has only sample data with desired result in the next sheet which I want to get from the list. Criteria means criteria for the VBA code should be operator's name in the VBA code to match/compare in the list.What I want is that the result which showing in red highlighted color in next sheet should be extract or come via using a VBA code. The VBA code should work like this first it should look for the operator name in the given list then should pulled all the comment data matching with the operator name in a new sheet.

    Like this
    #
    Operator Name Comment
    NBKS2QI James Done
    NBKSLVE Albert Not Done
    NBKTZ1P John Not Done
    NBKS2QI James Not Done
    NBKSLVE Albert Done
    NBKS2QI James Done
    NBKSLVE Albert Not Done
    Last edited by daksh1981; 04-21-2009 at 10:14 AM.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA code for extracting data from a list as per given criteria

    Sorry but I must be missing something - the two sets of data are basically the same, all that's been done is some columns have been removed.

    And I don't see any criteria.

  7. #7
    Forum Contributor daksh1981's Avatar
    Join Date
    04-15-2009
    Location
    India
    MS-Off Ver
    2003 & 2007
    Posts
    110

    Exclamation Re: VBA code for extracting data from a list as per given criteria

    You are right, I have just checked my attached file. I missed to include my criteria. Here is the updated sheet attached with the criteria included. Now what I want that the VBA code should pick those data from the Master Data whose operator name is in Criteria list , Operator's Name can be increase or decrease later, not other than that which falls under this list. I hope this time it is ok for you to understand what I actually want from the data. This time I have also used comments to make it more easy to understand
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: VBA code for extracting data from a list as per given criteria

    If you are going to use a pivot table anyway, why not use that on your original data to produce your result, its a lot faster than VBA will be!

    Since you can choose what data to include and filter on names?

  9. #9
    Forum Contributor daksh1981's Avatar
    Join Date
    04-15-2009
    Location
    India
    MS-Off Ver
    2003 & 2007
    Posts
    110

    Smile Re: VBA code for extracting data from a list as per given criteria

    Thanks for replying squiggler47. You are right I want to run a Pivot table. But the problem lies in my master file it is such a hug size, so if I have a VBA code it will automatically pull that data from the master file into result sheet & I will only run the create Pivot Macro from the result sheet for creating a pivot table. I tried many codes but I am not that much advance programmer. Please help me out to get a perfect VBA code for this.
    Last edited by daksh1981; 04-22-2009 at 01:51 AM.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA code for extracting data from a list as per given criteria

    Why not use advanced filter?
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor daksh1981's Avatar
    Join Date
    04-15-2009
    Location
    India
    MS-Off Ver
    2003 & 2007
    Posts
    110

    Question Re: VBA code for extracting data from a list as per given criteria

    Thanks for the code, it is working fine for only 50% it is pulling the operator's name in the Result Sheet , which what exactly I want, but I want the corresponding comments also in the next column for the operator's. I tired to customize the code but fail to get the desire result. Please help on it. I have attached the file, please have a look again on the Result file I have added a new comment & column.
    Attached Files Attached Files

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA code for extracting data from a list as per given criteria

    Well this code works fine for me - I don't know where the 3rd delete came from in your code.
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor daksh1981's Avatar
    Join Date
    04-15-2009
    Location
    India
    MS-Off Ver
    2003 & 2007
    Posts
    110

    Unhappy Re: VBA code for extracting data from a list as per given criteria

    Hi, Norie. Now I have used your code as it is in the attached sheet, but even after this this code is just giving me the Operator's name it is not giving the Comment for that operator in Column C , which I need in column C of my Result file. Please see the attached file.
    Attached Files Attached Files

  14. #14
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA code for extracting data from a list as per given criteria

    Could you try the code with the 'Result File' worksheet blank?

  15. #15
    Forum Contributor daksh1981's Avatar
    Join Date
    04-15-2009
    Location
    India
    MS-Off Ver
    2003 & 2007
    Posts
    110

    Smile Re: VBA code for extracting data from a list as per given criteria

    After deleting the value in Range A1:B8 in Result File Sheet, the code is working fine, but every time I have to manually delete the data from the range A1:B8 in Result File Sheet before running the code, so I used the below code before using the code for extracting data from the list. If you have any other suggestion please advice.

    Please Login or Register  to view this content.

  16. #16
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA code for extracting data from a list as per given criteria

    Why not just clear the cells in the worksheet 'Result File'?
    Please Login or Register  to view this content.
    This should work, unless you've other stuff happening on that sheet.

  17. #17
    Forum Contributor daksh1981's Avatar
    Join Date
    04-15-2009
    Location
    India
    MS-Off Ver
    2003 & 2007
    Posts
    110

    Thumbs up Re: VBA code for extracting data from a list as per given criteria

    I hope that this will ok. My query has resolved. Thanks for the support.

  18. #18
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA code for extracting data from a list as per given criteria

    Could you please tell us how it was resolved?

    All the code I posted was tested, so the only thing I can think is that you were doing something else that you didn't mention.

    This might be because you thought it wasn't relevant but you shouldn't assume something isn't relevant.

  19. #19
    Forum Contributor daksh1981's Avatar
    Join Date
    04-15-2009
    Location
    India
    MS-Off Ver
    2003 & 2007
    Posts
    110

    Thumbs up Re: VBA code for extracting data from a list as per given criteria

    Yes you are right, this was only a sample data. I was looking for a solution of a problem. Which I got upto some level, I am working on how to use criteria from a given list to get the desired result. For example in my sheet I was using Operator's name as a criteria for my result, now what I am testing that Is it possible to look for partially match criteria in the list. Like if Operator's name is some thing like this : James Smith NBKLV8P; California. Now I am testing will it be possible for my code that it will look for "NBKLV8P" as it's criteria for doing advance search for my result? If you have any suggestion please advice. You always proved a great help for me.
    Last edited by daksh1981; 05-15-2009 at 10:04 AM. Reason: Solved

  20. #20
    Registered User
    Join Date
    05-11-2016
    Location
    Bangalore
    MS-Off Ver
    2010
    Posts
    5

    Re: VBA code for extracting data from a list as per given criteria

    hi need a code to copy-paste data from one sheet to another
    Sheet 1 has A:M data, I need to filter column D particular criteria and select the data of Columns A & D to paste in Sheet 2.
    again repeat - need to filter column D another criteria and select the data of Columns A & D to paste in Sheet 2 with next available cell.
    again repeat - need to filter column E another criteria and select the data of Columns A & E to paste in Sheet 2 with next available cell.Capture.PNG
    Attached Images Attached Images
    Last edited by George Martin; 05-25-2021 at 05:05 AM. Reason: with a sample

  21. #21
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: VBA code for extracting data from a list as per given criteria

    Quote Originally Posted by George Martin View Post
    hi need a code to copy-paste data from one sheet to another...


    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ 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