+ Reply to Thread
Results 1 to 14 of 14

VBA to insert column based on condition for matching col data

  1. #1
    Registered User
    Join Date
    11-03-2017
    Location
    US
    MS-Off Ver
    7
    Posts
    23

    VBA to insert column based on condition for matching col data

    Hi,

    I want to insert a new column at the end into child sheet and rename as "My Output".
    In that column, I need to populate the flag 1,2, 3, 0 based on data matches between parent and child sheet. I have mentioned the criteria within the spreadsheet.

    Attaching sheet for reference

    The product searching should be based on pattern matching. It means if product name as 'Paracetamol' in child sheet is searching for the product column in master sheet and if the name found to be paracetamol syrup, then it should be considered as matching.( as part of it is matching). Similar condition applicable in vice versa

    Could anyone please help me.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: VBA to insert column based on condition for matching col data

    Can you give more details about the values 0,1,2 etc ...
    For example why to use value 2 for Diovan and Paracet ?
    - Battle without fear gives no glory - Just try

  3. #3
    Registered User
    Join Date
    11-03-2017
    Location
    US
    MS-Off Ver
    7
    Posts
    23

    Re: VBA to insert column based on condition for matching col data

    Thanks PCI for looking into my concern.

    I want to insert new column at the end of row and populate flag like 1,2, 0 based on below conditions
    Flag
    1 means if product (pattern match), route and country matches between child and parent
    2 means if product (pattern match) and country matches between child and parent where as route is blank or no value
    3 means if product (pattern match) and country matches between child and parent where as route is not matching
    0- mismatch

    Thanks in advance

  4. #4
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: VBA to insert column based on condition for matching col data

    What do you mean by "pattern match" ??

  5. #5
    Registered User
    Join Date
    11-03-2017
    Location
    US
    MS-Off Ver
    7
    Posts
    23

    Re: VBA to insert column based on condition for matching col data

    Its like the whole text from child sheet is matching with either full text or part of the text from master sheet (like operator)
    e.g "Paracetamol" from child sheet is matching with "Paracetamol syrup" which can be considered as full match.

    If you check the cell J2 value, it should be populated as value '1' because all three columns contain same text i.e.
    child sheet parent sheet Flag
    product route country Product route country
    paracetamol oral US Paracetamol syrup oral US 1 (as it is matching)


    Please check column J where I kept desired output

  6. #6
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: VBA to insert column based on condition for matching col data

    See the first piece of code for flag 1.
    Because the result is not the same some clarification is needed
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by PCI; 11-11-2017 at 07:53 PM.

  7. #7
    Registered User
    Join Date
    11-03-2017
    Location
    US
    MS-Off Ver
    7
    Posts
    23

    Re: VBA to insert column based on condition for matching col data

    Thank You so much PCI. I am currently testing it in my project.

    Could you please guide what code should be written to populate flag 2 and 3 (PID should be taken as group variable as the matching must be done within the group).

    Thanks once again for your great help and support

  8. #8
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: VBA to insert column based on condition for matching col data

    Before to finish Flag 2 and 3, I would like to be sure that flag 1 code is working properly:
    You add a specification about PID ...!

  9. #9
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: VBA to insert column based on condition for matching col data

    See here a remake taking care of PID and flag2...
    Result does not fit to your values ...!
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    11-03-2017
    Location
    US
    MS-Off Ver
    7
    Posts
    23

    Re: VBA to insert column based on condition for matching col data

    I am making the data as simple so that it will be easier to explain for every rows.
    Note:- Data from column D and C means product Paracetamol, Nimusulid and caffeine are sold in US available in A1.doc
    The A2 doc describes product Diovan and asthafen are sold in both UK and India. so while matching the product, any of the combination should be considered like UK-diovan or UK_Asthafen or
    India_diovan or India-Asthafen). See row number RW6 for reference.

    RW2:- Flag should be 1 as the data (US-Paracetamol-Oral) from child sheet matches with Master sheet (US-Paracetamol syrup-Oral)
    RW3:- Flag should be 0 as the data mismatch
    RW4:- Flag should be 0 as the data mismatch
    RW5:- Flag should be 2 as the data (UK-Diovan) from child sheet matches with Master sheet (UK-Diovan) and route column data is blank.
    RW6:- Flag should be 1 as the data (UK-Asthafen-sc) from child sheet matches with Master sheet (UK-Asthafen-sc)because this Asthafen is sold in two different country
    RW7:- Flag should be 0 as the product mismatch.
    RW8:- Flag should be 2 as the data (China-Atorvastatin) from child sheet matches with Master sheet (China-Atorvastatin) as the product is sold in both china and japan
    RW9:- Flag should be 1 as the data (China-Cycolpam Injection-sc) from child sheet matches with Master sheet (China-Cycolpam-sc)
    RW10:- Flag should be 0 as the product match but other two column value not matching or null value

    Column A should be considered as group variable as data is document specific (like A1.doc, A2.doc etc.)

    Please check the attached sheet for your reference.
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: VBA to insert column based on condition for matching col data

    It is a bit confusing:
    RW6:- Flag should be 1 as the data (UK-Asthafen-sc) from child sheet matches with Master sheet (UK-Asthafen-sc)because this Asthafen is sold in two different country
    => It is not UK

    RW9:- Flag should be 1 as the data (China-Cycolpam Injection-sc) from child sheet matches with Master sheet (China-Cycolpam-sc)
    => It means we have to search Cycolpam into Madter sheet but why not Injection ???

  12. #12
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: VBA to insert column based on condition for matching col data

    See attached the last revision
    In sheet "Info" is marked in Red when it must be clarified
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    11-03-2017
    Location
    US
    MS-Off Ver
    7
    Posts
    23

    Re: VBA to insert column based on condition for matching col data

    Thanks once again PCI for your continuous effort in looking into my query.

    RW6:- Flag should be 1 as the data (UK-Asthafen-sc) from child sheet matches with Master sheet (UK-Asthafen-sc)because this Asthafen is sold in two different country
    => It is not UK

    Clarificaton=> It means as per A2 document, the product ASTHAFEN is sold in both countries i.e. UK and India . Similar for Diovan product also.
    Therefore the macro should work taking both countries for searching in Master file in multiple combination like (UK-Diovan, UK-Asthafen, UK-Asthafen,India-Asthafen)


    RW9:- Flag should be 1 as the data (China-Cycolpam Injection-sc) from child sheet matches with Master sheet (China-Cycolpam-sc)
    => It means we have to search Cycolpam into Master sheet but why not Injection ???

    Clarificaton=> Yes you are correct. As cyclopam is available in market in injection or tablet format, my requirement is to search the active ingredient.
    Therefore the macro should either match the complete text (i.e. Cycolpam Injection) or if it is not found, search only the first word(i.e. cyclopam).

    I hope this is fine now.

    Thanks once again

  14. #14
    Registered User
    Join Date
    11-03-2017
    Location
    US
    MS-Off Ver
    7
    Posts
    23

    Re: VBA to insert column based on condition for matching col data

    Hello PCI

    I am testing the program in my project sheet (attachment for reference).
    May I request you to check the flag once again for 1 and 2 as it is currently not populating.

    For RW8, the macro should populate 2 as the data (France-GLIBENCLAMIDE) from child sheet is matching with data (France-GLIBENCLAMIDE) from master sheet where as forumulation field is blank.
    For RW7, it should populate 1.

    Please check once again.

    Thanks in advance
    Attached Files Attached Files

+ 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] Insert column and populate data based on condition
    By tikistat in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 11-09-2017, 12:51 PM
  2. Insert data rows based on a condition for measured data
    By JosipK in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-10-2015, 02:09 PM
  3. Replies: 2
    Last Post: 04-11-2014, 12:18 PM
  4. [SOLVED] Insert Row based on Condition and add data in the newly created rows
    By Omariss in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-16-2013, 04:27 AM
  5. Copy required data based on matching condition
    By raghav.k in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-25-2011, 01:35 PM
  6. insert text based on vlookup condition in two column
    By isabella in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-10-2010, 09:19 PM
  7. matching data based on column
    By Mr_Shore in forum Excel General
    Replies: 1
    Last Post: 09-25-2008, 06:30 AM

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