+ Reply to Thread
Results 1 to 46 of 46

Macro to filter and copy data from one sheet to another sheet

  1. #1
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Macro to filter and copy data from one sheet to another sheet

    I need vba to filter data and Copy in a new sheet

    I have a excel sheet with 2 sheets (Data) and (Results).

    First
    In Sheet (Data), I want to apply filter in cell G1 wth Criteria is Begins with “Resolved” and “Sent” and want to copy visible records from A to E and paste in Sheet (Results) from cell A1.
    Also assign new serial number starting from 1 from cell A2 to till the end of last record.

    If no records, then show message box “No record found” and exit macro. If record found then do above task and move to Second

    Second
    In Sheet (Data), I want to apply filter in cell G1 with Criteria is Begins with “Resolved” and “Sent” and in cell F1 “Yes” and want to copy visible records from A to E and paste in Sheet (Results) 4 lines after the above pasted records.

    Also assign new serial number starting from 1 for newly pasted records in column A.

    If no records, then show message box “No second record found” and execute only First macro and exit. If record found then do above task and move to Third


    Third

    I want to add one sentence in excel sheet (Results) between both first and second i.e. “Below records are YES Records and Below records are excludes no Records”

    If there is no record found as per Second filter then ignore Third

    Please refer attachment for example.

    Request you to provide code
    Attached Files Attached Files

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    Try:
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    hey thanks.

    But shows error in line

    .AutoFill .Resize(rowCount, 1), xlFillSeries

    while running the code in attached data

    can you please check?
    Attached Files Attached Files

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    Try:
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    Hey again it shows error in line

    .AutoFill .Resize(rowCount, 1), xlFillSeries

    while running the code in attached data

    can you please check?
    Attached Files Attached Files

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    Try:
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    Hey in Second part heading is missing

  8. #8
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    also when iam running the macro while i am on sheet Results it shows "No Records". it works only when iam on sheet data

  9. #9
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    We'll get there sooner or later!
    Please Login or Register  to view this content.

  10. #10
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    Make sure that the "Data" sheet is always the active sheet when you run the macro.

  11. #11
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    Hey sorry, it works perfectly.

    Can you please help me with one more code in continuation.

    i need code to give border line to the copied data in sheet "results" as per attachment
    Attached Files Attached Files

  12. #12
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    This macro should also work regardless of which sheet is the active sheet.
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    Dear Mumps1,
    Thank you very much for your code. This is what Exactly I wanted.

    I need one last help from you. Trust me I will not ask anything more.

    Your code is perfect is per my requirement.

    Can you please modify the code for below situation.

    In case the set of first range and second range is same to same (as given attachment Sheet “Results”,
    Then paste only the first range (ignore second range). Also Add text 2 rows after the last record “ NO OTHER RANGES ARE AVAILABLE”

    Optional:
    Also If have any idea about the macro integration with Outlook, please help me with code to paste both the ranges in outlook email body (not as attachment).
    Please help. This will be my last requirement
    Attached Files Attached Files

  14. #14
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    This should take care of your first request:
    Please Login or Register  to view this content.
    I'm afraid that I have little experience using Excel with Outlook. A quick Google search should give you what you are looking for.

  15. #15
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    The previous macro I suggested will only work properly if all the cells in column F say "Yes". Try this revised macro:
    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    Hey,
    I think there is some problem with the code.

    it paste only the first range

  17. #17
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    attached sample file for your reference.

    Please help
    Attached Files Attached Files

  18. #18
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    Sorry,

    Refer this attachments. Earlier attached wrong file
    Attached Files Attached Files

  19. #19
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    Try:
    Please Login or Register  to view this content.

  20. #20
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    Dear Mumps1,

    I am still not able to figure out the problem in the code.

    Please refer attachment.

    In My sheet there is one "yes" in column F. But while running the code it shows "No Yes Records Found"

    can please correct the data. I have attached Example file.
    Attached Files Attached Files

  21. #21
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    Give this one a try:
    Please Login or Register  to view this content.

  22. #22
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    Dear Mumps1,
    I am extremely sorry to bother you.

    The above issue has been resolved. But one more problem has been raised.

    please find attachment. I have mentioned earlier that If both the ranges are same then there should be only one range in the sheet Results.

    Please refer attachment. I have given example.
    Attached Files Attached Files

  23. #23
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    Please Login or Register  to view this content.

  24. #24
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    yes somehow it works. Along with message box "No 'Yes' records found or both ranges are the same."

    I also wanted to insert the same line ("No 'Yes' records found or both ranges are the same.") above the data range. Please insert 3 rows above the data and insert this sentence in cell B2.

  25. #25
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    Also let me know if I want to apply first filter in column H instead G which line of code to be changed and how?

  26. #26
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    Please Login or Register  to view this content.
    To change the column to filter:

    Change the values in red: column letter and column number:

    Please Login or Register  to view this content.

  27. #27
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    hey got it. wants border line only within a table. in the above code it gives border line to empty cell also above first range.

    Inserting 3 Rows above is perfect.

    After inserting 3 above rows insert sentence "No 'Yes' records found or both ranges are the same." in b2 .

    Please note need border line only in table

  28. #28
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    Replace this line of code:
    Please Login or Register  to view this content.
    with this one:
    Please Login or Register  to view this content.

  29. #29
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    Dear Mumps1,
    I am extremely sorry to bother you. It might irritate you.

    i have mentioned by requirement in attachment in details.

    There are possibility of 3 scenarios.

    I and I have given examples for data format for 3 scenarios. Please change your code accordingly.

    Please note the heading text and cell number of Heading etc. Dont change the position. This is going to be final format

    Please Please Please Please Please
    Attached Files Attached Files

  30. #30
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    I have to go out in a short while and I'll be out of town for a few days. I will have a look at the file when I return and get back to you.

  31. #31
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    Try:
    Please Login or Register  to view this content.

  32. #32
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    You Boss!!! Genius!!! Wonderful!!!!

    Thank you so much friend.

    Thanks a ton. It works perfectly.

    Thank you very much for your help.

    I really appreciate your tech skill and patience.

  33. #33
    Registered User
    Join Date
    02-28-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2010
    Posts
    100

    Re: Macro to filter and copy data from one sheet to another sheet

    Genius You are ... Great Mr.Mumps!

  34. #34
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    @saravanan1981: You are very welcome.
    @perpectuals: I'm not sure about "genius" but thank you for the kind words.

  35. #35
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    Hi Mumbps,

    I am facing some problem again.

    I am getting error on this line while running code in attachment.

    .AutoFill .Resize(LastRow2 - 4, 1), xlFillSeries

    Please refer attachment as well.
    Attached Files Attached Files

  36. #36
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    Replace this part of the code:
    Please Login or Register  to view this content.
    with this:
    Please Login or Register  to view this content.

  37. #37
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    hi Mumps,

    Connecting after a long time.

    I am facing a small problem in a code.

    I have added one more filter criteria as below
    Sheets("Data").Range("A1:I" & LastRow1).AutoFilter Field:=6, Criteria1:="=India"


    and changed the column numbers accordingly. But it show no records. below is my new code.

    Can you please help me on this?



    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  38. #38
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    Try:
    Please Login or Register  to view this content.

  39. #39
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    Hi,

    Thank you for your revert

    I am getting an error on below line

    .AutoFill .Resize(LastRow2 - 4, 1), xlFillSeries


    If there is no records in the name of India, then should show msg box stating no records found.

    How to do that? can u please help me?
    Attached Files Attached Files

  40. #40
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    Try:
    Please Login or Register  to view this content.

  41. #41
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    Hi,
    I am getting an error on below line.

    Sheets("Data").Range("A1:E" & LastRow1).SpecialCells(xlCellTypeVisible).Copy Sheets("Results").Cells(4, 1)


    Pls help
    Attached Files Attached Files

  42. #42
    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,929

    Re: Macro to filter and copy data from one sheet to another sheet

    Apologies for the "start a new thread" request, I had not noticed that this is, in fact, your thread (lust a little old now)
    Last edited by FDibbins; 07-18-2018 at 11:25 AM.
    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

  43. #43
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    That line of code is looking for the sheet "Results" which is missing. Please add the sheet and name it "Results"

  44. #44
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    Hi Mumps,

    Yes identified that later. Thanks for your help.

    I just need one last help from you.

    In attached file in Sheet "Results" Records under "Below records are 'YES' Records excluding 'NO' Records", Border lines are not coming for all records.

    Border line is appearing for only heading and first record.

    Can you let me know how to apply border line for all 5 records.

    Also number of records might change case to case as per the changes in data.

    So border line should apply dynamically in visible records.

    Please help buddy
    Attached Files Attached Files

  45. #45
    Forum Contributor
    Join Date
    11-17-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    365

    Re: Macro to filter and copy data from one sheet to another sheet

    No Worries sir

  46. #46
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to filter and copy data from one sheet to another sheet

    Try:
    Please Login or Register  to view this content.

+ 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] Need Macro to pull data from 1 sheet and filter into another sheet
    By asmithusa in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-15-2014, 04:51 PM
  2. [SOLVED] Run a loop to slected data then filter on another sheet and copy to another sheet
    By af_lel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-21-2013, 07:10 AM
  3. Replies: 1
    Last Post: 06-05-2013, 07:03 AM
  4. Copy Data from Multiple weekly Sheet to Monthly sheet and filter the data
    By santhoshjoseph in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-06-2012, 07:07 AM
  5. [SOLVED] Macro to Copy Data from one Sheet A to Sheet B based on value in cell on sheet A
    By scass in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-11-2012, 07:21 PM
  6. [SOLVED] MACRO to FILTER data then copy the data to another SHEET.
    By mareuko31 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-15-2012, 08:07 PM
  7. Filter, copy filtered data into another sheet, create a file of that sheet..
    By titushanke in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-17-2012, 02:26 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