Concatenate Cells

dandy

New Member
Joined
Apr 3, 2017
Messages
22
I have code that pulls from a database and inputs into an excel sheet (shown below).


Code:
 Selectstring = "SELECT " & c.Item("Ticket1") & _
                   ", " & c.Item("Description")

    fromString = "FROM " & ibmLib1 & "." & t.Item("NCType") & " " & t.Item("NCType") & _
                 ", " & ibmLib1 & "." & t.Item("NCRs") & " " & t.Item("NCRs")

    whereString = "WHERE " & c.Item("Ticket3") & "=" & c.Item("Ticket1")

    strSql = Selectstring & " " & fromString & " " & whereString
    
        '################PERFORM THE QUERY################
    Set conn = Open400Conn()
    Set rs = Query(conn, strSql)
    descTab.Range("A1").Value = "Ticket"
    descTab.Range("B1").Value = "Description"
    descTab.Range("A2").CopyFromRecordset (rs)
    conn.Close


The way the database is setup, it only can record a certain amount of characters per line and so I get multiple lines for one record (example below)


[TABLE="class: grid, width: 300, align: left"]
<tbody>[TR]
[TD]A
[/TD]
[TD]B
[/TD]
[/TR]
[TR]
[TD]Ticket
[/TD]
[TD]Description
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]test
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]CN 11: 1-22 check 1.3504 or
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD].0084 o/max; CN 10: S/N 14
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]check 0.0303 or .003 o/max
[/TD]
[/TR]
</tbody>[/TABLE]











I would like the query to say something like "If there is a duplicate value in column A, combine all the text in the corresponding cells into one line."

So instead of having it like it is shown directly above, it would come out like this:

[TABLE="class: grid, width: 700, align: left"]
<tbody>[TR]
[TD]A
[/TD]
[TD]B
[/TD]
[/TR]
[TR]
[TD]Ticket
[/TD]
[TD]Description
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]test
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]CN 11: 1-22 check 1.3504 or .0084 o/max; CN 10: S/N 14 check 0.0303 or .003 o/max
[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,225,754
Messages
6,186,825
Members
453,377
Latest member
JoyousOne

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top