+ Reply to Thread
Results 1 to 8 of 8

VBA to Merge data, remove duplicates and sort

  1. #1
    Registered User
    Join Date
    02-02-2014
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    67

    VBA to Merge data, remove duplicates and sort

    Hi, attached is a sample workbook. Could I please have some help with a macro to combine data from two worksheets and then getting rid of duplicate rows as well as sorting based on a field. I've got two data tabs - 'Actuals' and 'Budget with a number of columns but they share the same columns (E:H) as shown in the file. I need to pull data in those identical columns into a consolidated worksheet. Since there can be duplication of rows from the two tabs (exactly the same content across all the columns specified), I would need to remove the duplicated rows and then sort them based on data in column E.

    I have also mentioned my requirement on the 'consol' tab.

    I've tried recording a macro but it isnt dynamic enough when the number of rows shift from month to month and I'm having to adjust the variables every month. Any help would be most appreciated.
    Attached Files Attached Files

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

    Re: VBA to Merge data, remove duplicates and sort

    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
    Registered User
    Join Date
    02-02-2014
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: VBA to Merge data, remove duplicates and sort

    Hi, thanks for your prompt response....the code runs very well. However it doesnt seem to clear the consol data before running the code for merging? So if I hit the run button twice, it appends the data to the existing rows...so it keeps multiplying. I guess we need a clearcontent somewhere in there?

    Otherwise, it seems to run like a dream. Thank you. Look forward to your response.

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

    Re: VBA to Merge data, remove duplicates and sort

    Try:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-02-2014
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: VBA to Merge data, remove duplicates and sort

    Hi, thanks for the above. The Company code in the first column is being copied over to the 'consol' tab as a number and not as a text, even if it is a text in the other two tabs? Is there anything within the code that needs to be corrected so it picks the formatting from the other tabs?

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

    Re: VBA to Merge data, remove duplicates and sort

    Try:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-02-2014
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: VBA to Merge data, remove duplicates and sort

    Hi, apologies for the late response. Thanks for your help....its been immense and managed to sort it out for me. On the last query (before I got a response from you), I changed the 'DataOption:=xlSortNormal' within the Sort code to read 'DataOption:=xlSortTextAsNumbers' and for some reason it worked (not sure why as it was reporting text as numbers previously and the terminology 'SortTextAsNumbers' seems to indicate the opposite)!! But as it works, I've left it at that. I might have to revisit the above if the macro starts failing again.

    But thank you so much for your help....much appreciated.

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,037

    Re: VBA to Merge data, remove duplicates and sort

    You are very welcome.

+ 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. Replies: 6
    Last Post: 11-25-2015, 02:08 AM
  2. [SOLVED] Remove duplicates and sort data for populating a combobox using VBA
    By newbi004 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-26-2013, 05:28 AM
  3. Copy Data, Remove Duplicates & Sort Ascending
    By DrifterX in forum Excel General
    Replies: 0
    Last Post: 04-07-2013, 05:44 PM
  4. [SOLVED] Remove rows based on duplicates in certain columns, and merge data from another column
    By yanagi600 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 01-02-2013, 04:17 PM
  5. Sort - Merge Current Data into blank cells, remove duplicate information
    By cannedyams in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-27-2012, 04:08 PM
  6. Copy Data, Remove Duplicates & Sort Ascending
    By knightcloud in forum Excel General
    Replies: 1
    Last Post: 09-09-2010, 12:28 PM
  7. Remove duplicates from col.A and merge col.B
    By wali in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 08-13-2008, 04:54 PM

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