+ Reply to Thread
Results 1 to 8 of 8

Macro for looping through cells and concatenating based on criteria

  1. #1
    Registered User
    Join Date
    05-29-2014
    Posts
    4

    Macro for looping through cells and concatenating based on criteria

    Hi all,

    I'm currently trying to take some simple tabular data and put it into a more useful format using concatenation. I have been trying to create a macro to do this but have only found partial code online which hasn't really helped much. Here is an example of the data I would like to clean up from Sheet 1 (also attaching image)

    A B C
    Skill_1 M1 Experience
    Skill_2 M2 Exposure
    Skill_3 M1 Exposure
    Skill_4 M3 Education
    Skill_5 M2 Exposure
    Skill_6 M3 Education
    Skill_7 M1 Experience


    sheet 1.jpg

    I'm looking to create a macro that will run through this data and take all cells in column A where the corresponding cells in columns B and C = "M1" AND "Experience", respectively, and concatenate them (separated by commas) in a new sheet. So in this example, Skill_1 and Skill_7 would be concatenated in a new cell in Sheet 2. I'm looking to do this for all possible combinations of column B and C values. The final output in Sheet 2 would look as follows:


    M1 M2 M3
    Experience Skill_1, Skill_7
    Exposure Skill_3 Skill_2, Skill_5"
    Education Skill_4, Skill_6
    Expectations


    sheet 2.jpg

    Any help would be much appreciated. Thanks!
    Attached Images Attached Images

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Macro for looping through cells and concatenating based on criteria

    no jpg please but excel sample file
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    05-29-2014
    Posts
    4

    Re: Macro for looping through cells and concatenating based on criteria

    I have attached the sample file. The Data tab contains what I need to cleanup and the Sample tab contains what I need the output to look like. Thanks!

    concat_loop.xlsx

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Macro for looping through cells and concatenating based on criteria

    3 levels and 4 categories ? or more ?

  5. #5
    Valued Forum Contributor Hawkeye16's Avatar
    Join Date
    02-27-2013
    Location
    Holland
    MS-Off Ver
    ├•┤ Pew Pew
    Posts
    441

    Re: Macro for looping through cells and concatenating based on criteria

    Is this what you are looking for? It is very similar to something I wrote for someone last week and posted on this forum - although finding it in a search in a timely manner is not always easy.

    It is a UDF that takes 5 inputs similar to a SumIfs or CountIfs (Condition 1 Range, Condition 1, Condition 2 Range, Condition 2, Concatenation Range)
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Macro for looping through cells and concatenating based on criteria

    try attached
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    05-29-2014
    Posts
    4

    Re: Macro for looping through cells and concatenating based on criteria

    Hawkeye -- Thanks for the help. I actually saw that thread for the UDF but unfortunately while it does solve the sample, I can't use it for my actual data. This is going to be used by a lot of different users who will essentially just enter data in one worksheet, click a button, and then see the results on another.

  8. #8
    Registered User
    Join Date
    05-29-2014
    Posts
    4

    Re: Macro for looping through cells and concatenating based on criteria

    This is great! This is exactly what I need. Now I just need to make sure I understand the code and can replicate on a larger scale. Thanks!!

+ 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] Looping through a database and analyzing cells based on criteria
    By AZ-XL in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 04-08-2014, 01:31 PM
  2. Replies: 3
    Last Post: 09-12-2013, 06:50 PM
  3. Help Required - Concatenating cells contents into single cell, based on an ID
    By mharis in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-31-2013, 07:49 AM
  4. Replies: 5
    Last Post: 12-31-2011, 06:10 AM
  5. looping through excel cells based on criteria using VBA
    By born2achieve in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-07-2008, 01:24 AM

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