+ Reply to Thread
Results 1 to 24 of 24

[Request for Macro] Merge Similar Rows to 1 Row

  1. #1
    Registered User
    Join Date
    01-20-2017
    Location
    Philippine
    MS-Off Ver
    2016
    Posts
    15

    [Request for Macro] Merge Similar Rows to 1 Row

    Hello Guys, I would just like to ask help from pro excel users especially to those familiar with VBA. I have approximately 35k entries similar to the image below. What I want to happen is to create a Macro to combine rows with similar values in the following fields: Facility, Generic Name, Price, Brand, Manufacturer, Supplier and Mode of Procurement. While the values from the Quantity field shall be combined and be reflected in the row with the earliest date. The control numbers should also be consolidated in the row with the earliest date and must be separated by comma (,). Other rows where the Quantity and Control Number was extracted should be deleted.

    Please see the image if my description is unclear. I also attached in this post the copy of the file.

    I want this to loop over the 35k entries.

    Thank you.


    Untitled.jpg
    Attached Files Attached Files

  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: [Request for Macro] Merge Similar Rows to 1 Row

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    If posting code please use code tags, see here.

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

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    Try
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-20-2017
    Location
    Philippine
    MS-Off Ver
    2016
    Posts
    15

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    Hi Jindon,

    Thanks for the reply. It worked on my test file however when I pasted it on my actual file it says subscript out of range.
    Last edited by flaire14; 08-17-2017 at 02:42 AM.

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

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    If you are talking about the different file, no idea.

  6. #6
    Registered User
    Join Date
    01-20-2017
    Location
    Philippine
    MS-Off Ver
    2016
    Posts
    15

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    No, its similar with the file im working with. However my example is with complete data in it. My actual file have blank cells in it specifically in the Brand and Manufacturer. Please see the image how my actual data looks like.

    Quote Originally Posted by jindon View Post
    If you are talking about the different file, no idea.
    Untitled2.jpg

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

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    No body want to work with picture.

    If you upload a workbook with EXACT layout of raw data and the EXACT result that you want, it may help.
    As long as data type are the same and showing the clear logic, dummy data and only few rows are acceptable.

  8. #8
    Registered User
    Join Date
    01-20-2017
    Location
    Philippine
    MS-Off Ver
    2016
    Posts
    15

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    Okay sorry I am new of asking these kind of things. Please give me 30 mins I'll prepare a dummy table exactly the same as the actual data.

    Quote Originally Posted by jindon View Post
    No body want to work with picture.

    If you upload a workbook with EXACT layout of raw data and the EXACT result that you want, it may help.
    As long as data type are the same and showing the clear logic, dummy data and only few rows are acceptable.

  9. #9
    Registered User
    Join Date
    01-20-2017
    Location
    Philippine
    MS-Off Ver
    2016
    Posts
    15

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    Jindon, sorry for the wait.

    Kindly see the attached dummy file I made. It has the exact table of my actual file. Please be aware of the change in Column Headers and their positions.

    facilityname = Facility
    po_num = Control No.
    po_date = Date
    drugname = Generic Name
    Acquisiton = Price
    Units = Quantity
    brand = Brand
    manu_name = Manufacturer
    sup_name = Supplier
    biddingdesc = Mode of Procurement

    New Fields Included:
    LOCAL
    username
    Validated

    Okay, I want to maximize your kindness so may I include functions in the macro:

    The key function of the macro should merge rows with similar values in specific fields which are:
    1. facilityname
    2. drugname
    3. Acquisition
    4. Brand
    5. manu_name
    6. sup_name
    7. biddingdesc
    8. LOCAL
    9. Validated Value:YES
    a. If the Value in the Validated field is No, then no merging should happen even if Fields 1 - 9 are similar (including the No Value in the Validated Field)

    Prior to merging:

    1. Identify and delete double entries. It can be identified if the po_num and po_date is also similar in addition with the required fields for merging. One entry must be deleted

    Merging should consolidate the following information:
    1. All rows with similar data shall be merged on the row with the earliest date.
    2. po_num shall be consolidated in row with the earliest date separated with comma (,)
    3. Units shall be summed in the row with the earliest date
    4. username shall also be consolidate with backslash (/), remove similar username (e.g. instead of jeff / jel / jeff = > jeff / jel)
    5. If an entry has similar data (1-3, 5-9 fields) except 4 (Brand Name) because it is blank, merging is acceptable except for case that, two or more brand names matches the said entry. If it happens that it is the earliest date among the similar rows, then it shall inherit the brand name of the latter.
    Updated:
    6. All Rows where the po_num, units and username was extracted should be deleted.

    When not to merge:
    1. As per 9.a If the Value in the Validated Field is No regardless if similar rows are identified.

    Furnishing:
    1. Apply =Proper like command in the Brand Field.

    I greatly appreciate your help.

    Thank you!


    Quote Originally Posted by jindon View Post
    No body want to work with picture.

    If you upload a workbook with EXACT layout of raw data and the EXACT result that you want, it may help.
    As long as data type are the same and showing the clear logic, dummy data and only few rows are acceptable.
    Attached Files Attached Files
    Last edited by flaire14; 08-17-2017 at 01:09 AM. Reason: Missed one detail of the requested macro.

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

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    Confusing 9.a
    You said
    9. Validated Value:YES
    a. If the Value in the Validated field is No, then no merging should happen even if Fields 1 - 9 are similar (including the No Value in the Validated Field)
    .
    .
    .
    When not to merge:
    1. As per 9.a If the Value in the Validated Field is No regardless if similar rows are identified.
    But your results include "NO" in Validated column.

  11. #11
    Registered User
    Join Date
    01-20-2017
    Location
    Philippine
    MS-Off Ver
    2016
    Posts
    15

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    Yes it means that no action shall be done and leave it as it is. Btw I updated my details, I forgot including that the rows with their data extracted needs to be delete. Similar to what I've asked earlier.
    Last edited by flaire14; 08-17-2017 at 01:19 AM.

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

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    I don't know what is wrong.
    The results are not the same as yours.
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    01-20-2017
    Location
    Philippine
    MS-Off Ver
    2016
    Posts
    15

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    I did run the macro and this what I think what happened.

    1. It did not scan for double entries to delete it first. Check Cell B5, it has same po_num.
    2. Also in this:
    "5. If an entry has similar data (1-3, 5-9 fields) except 4 (Brand Name) because it is blank, merging is acceptable except for case that, two or more brand names matches the said entry. If it happens that it is the earliest date among the similar rows, then it shall inherit the brand name of the latter."
    The 6th Row should merge with the 5th row if this will work.
    3. It does not identify earlier date properly. Check Cell C13.

    Untitled3.jpg
    Last edited by flaire14; 08-17-2017 at 02:40 AM.

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

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    Can you just edit all your posts and remove the full quote of my posts?
    The forum doesn't like it.

  15. #15
    Registered User
    Join Date
    01-20-2017
    Location
    Philippine
    MS-Off Ver
    2016
    Posts
    15

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    No worries

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

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    5. If an entry has similar data (1-3, 5-9 fields) except 4 (Brand Name) because it is blank, merging is acceptable except for case that, two or more brand names matches the said entry. If it happens that it is the earliest date among the similar rows, then it shall inherit the brand name of the latter.
    If you look at the row 4 of your result, it merges, but not mine.
    What happens if more than 2 brands are different but the all others are the same?

  17. #17
    Registered User
    Join Date
    01-20-2017
    Location
    Philippine
    MS-Off Ver
    2016
    Posts
    15

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    If two brands are different, it shouldn't merge. However, if its only different because the other one is blank, then merging is acceptable.

    If this is applied, there is a possibility that the merged row will have blank Brand field, specially when the row that does not have the Brand happens to be the row with the earliest date. It will be solved by getting the Brand from other rows where the po_num, unit and username was extracted.
    Last edited by flaire14; 08-17-2017 at 03:18 AM.

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

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    That makes complicate.

    Loop all the rows to find the dups with "YES", and count different brands.
    When blank in brands found with other fields are the same and the brands are only one, merge, otherwise no merge.

    It that what you want?

  19. #19
    Registered User
    Join Date
    01-20-2017
    Location
    Philippine
    MS-Off Ver
    2016
    Posts
    15

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    I really appreciate your time and effort. I'm sorry if I am not good at explaining. Please bear with me.

    Yes I want to loop all rows to find dupes with "Yes", No counting of different brands.
    Duplicates should be deleted.

    I think we should separate the process of finding dupes. It think it will complicate things if we join it together with the merge process. And finding dupes should come first before merging.

    When blank in brands found with other fields are the same and the brands are only one, merge, otherwise no merge.
    Yes for this.

    PS: If you need me to illustrate it, please tell me.

  20. #20
    Registered User
    Join Date
    01-20-2017
    Location
    Philippine
    MS-Off Ver
    2016
    Posts
    15

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    Up for this!

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

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    Test this hard.
    Please Login or Register  to view this content.
    Last edited by jindon; 08-18-2017 at 11:28 PM.

  22. #22
    Registered User
    Join Date
    01-20-2017
    Location
    Philippine
    MS-Off Ver
    2016
    Posts
    15

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    Whoa I was overwhelmed with the codes Thank you.

    I run the codes and here's the problem's I've encountered. Please be guided by the image.

    a. Cell F3 (Wrong Value): It should be 1800 rather than 1200.
    b. Cell B5 (Ordering Error): po_num 2016-08-001 should come first than 2016-09-004 because 2016-08-001 has earlier date.
    c. Cell C5 (Date Value is not the earliest date): The earliest date is 8/22/2016 from po_num 2016-08-001.
    d. Cell F5 (Wrong Value): It should be 800 rather than 1000.
    e. Cell F9 (Wrong Value): It should be 1476 rather than 664.

    I don't know if this may help but I noticed an error in the quantity value if it tries to check the validated field (F3 and F9) and also when dealing with duplicates (F5). With B5 and C5, I don't know because other merges of po_num and po_date are correct.

    Moreover, it created an additional sheet that I think is needed for the process, can it be deleted automatically after the macro runs? Also the 2 helper column on the rightmost part of table.

    Untitled4.jpg

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

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    1) Sub test, change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    2) GetRow peocedure, change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  24. #24
    Registered User
    Join Date
    01-20-2017
    Location
    Philippine
    MS-Off Ver
    2016
    Posts
    15

    Re: [Request for Macro] Merge Similar Rows to 1 Row

    Sugoi! It worked! I'm crying Jindon-sama. Now I'll apply this on my 35k entries. I'll make a feedback once I'm done validating.

    Domo Arigato Gozaimasu!

+ 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. "merge" similar rows in pivot table?
    By rahel.ba in forum Excel General
    Replies: 1
    Last Post: 05-30-2023, 11:03 AM
  2. Hiding rows with a macro or similar
    By ChrisGlad in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-17-2016, 01:46 PM
  3. How to merge rows that have similar location names
    By aleanboy in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2014, 01:57 PM
  4. [SOLVED] VBA Request - Merge data in the rows based on certain conditions.
    By spiwere in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-12-2013, 09:59 AM
  5. Replies: 2
    Last Post: 01-22-2013, 11:37 AM
  6. Request Macro for Merge Text file
    By ganeshinscribe in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-21-2012, 04:25 AM
  7. [SOLVED] Merge rows with similar data
    By Shailesh Gattewar in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-10-2005, 02:06 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