-1

In excel sheet I have cells with mulitple comma separated values. I want to concatenate the corresponding values of two cells. Example:

Cell_A1 (A,B,C,D) and Cell_B1 (E,F,G,H)  
Then in Cell_C1 it should be (AE,BF,CG,DH). 
Dave
  • 25,297
  • 10
  • 57
  • 69
Raw
  • 15
  • 1
  • 4
  • use the mid formula to split the values in cell A1 and B1 into different cells and then concatenate the results in C1 as desired... Have you tried anything at all. Please show what have you tried. – Prasanna Aug 23 '14 at 14:27
  • I tried to split them using "text to columns" option but as there are from 1 to 130 values in a single cell so its not making sense to join them in what manner after splitting. there must be some formula to take respective values and concatenate and print. – Raw Aug 25 '14 at 05:59
  • Is this question a follow up on http://superuser.com/questions/801559/excel-formula-to-compare-single-value-in-one-cell-with-multiple-values-in-other where you want to add another column of detail but perform the same task (just over 2 columns instead of 1)? – Dave Aug 26 '14 at 08:26

2 Answers2

0

Nice question. Please find the image below for your answer.
Note-1: Add a comma as the last character to your cells which you want to split - otherwise you will get #value error in the last row.
split the contents of the cell

Now you have to do the same thing with your other cell and obtain a similar result.

As a last part use the concatenate function to join pairs from the two columns and get your end result.
Concatenate would look something like this (assume cell A2 contains the comma character)
=concatenate(C3,$A$2,E3) Also assumed that E3 contains the result which has to be joined with C3.
If you have any questions feel free to comment.

Prasanna
  • 4,036
  • 5
  • 34
  • 51
  • Thanks for your efforts Prasanna but Dave have better solution and understanding for my question. I have thousands of rows and upto 130 values in one cell to compare. – Raw Aug 27 '14 at 08:06
0

This does it

Option Explicit

Sub DoTheThing()

Dim row As Integer
row = 1 ' WHAT IS THE STARTING ROW

'Let's clear the answers

Range("D:F").Cells.Clear

Do While (Range("A" & row).Value <> "")

    Dim lookUpValue As String
    lookUpValue = Range("A" & row).Value

    Dim vals() As String
    vals = Split(Range("B" & row).Value, ",")

    Dim result As String
    result = ""

    Dim i As Integer

    For i = 0 To UBound(vals)

        If CSng(lookUpValue) >= CSng(vals(i)) Then
            result = result & "Yes, "
        Else
            result = result & "No, "
        End If

    Next i

    result = Trim(result)
    result = Left(result, Len(result) - 1)

    Range("D" & row).Value = result

    result = "" ' reset it
     Dim valD() As String
    valD = Split(Range("C" & row).Value, ",")

     For i = 0 To UBound(valD)

        If CSng(lookUpValue) <= CSng(valD(i)) Then
            result = result & "Yes, "
        Else
            result = result & "No, "
        End If

    Next i

    result = Trim(result)
    result = Left(result, Len(result) - 1)

    Range("E" & row).Value = result


'finally

    Dim splitD() As String
    splitD = Split(Range("D" & row).Value, ",")


    Dim splitE() As String
    splitE = Split(Range("E" & row).Value, ",")

    result = ""

    Dim length As Integer
    length = UBound(splitD)
    For i = 0 To length 'both should have the same values according to @Raw
        If (i = length) Then
            Range("F" & row).Value = Range("F" & row).Value & splitD(i) & splitE(i)
        Else
            Range("F" & row).Value = Range("F" & row).Value & splitD(i) & splitE(i) & ","
        End If
    Next i

    row = row + 1

Loop

End Sub

Before

enter image description here

After

enter image description here

Dave
  • 25,297
  • 10
  • 57
  • 69
  • Dave Thanks for your efforts. as I told earlier the answer provided by you solved 1 part of my problem i.e getting yes or no on comparison of value in Column A with values in column B. 2nd thing we have to do is comparison of value in Column A with values in column C but with <= rather than >=. After that we will get two new columns as having multiple values of "yes" or "no" like D1 (yes,yes,no,no) and E1(no, yes, no, no). Here comes the 2rd part of my problem which I asked here to join corresponding values within D1 and E1 to obtain new data in F1 as (yesno, yesyes, nono, nono). Thats it. – Raw Aug 27 '14 at 08:00
  • So,assume A3 is 50. B3 is `10, 60` and C3 is `60,10`. Should the value in D3 be YesNo,NoYes ? – Dave Aug 27 '14 at 10:16
  • 1
    No Dave. If we assume as you said, then value in D3 will be (Yes, No) (i.e. 50 >= 10, 60) and in E3 it will be (Yes, No) (i.e 50 <= 60, 10). Finally in F3 it will be (YesYes, NoNo). And it will be great if we can directly obtain that value of F3 by some formula. – Raw Aug 28 '14 at 11:55
  • Please note that in my data, the comma separated values in each cell are in ascending order without any repeats – Raw Aug 28 '14 at 12:15
  • @raw, I made an update to my post, see the new code above – Dave Aug 29 '14 at 07:26
  • Its working fine. Doing exactly what I want to do. Thanks a lot. – Raw Sep 01 '14 at 06:07