Need to pull data from a column and string it together

tbednarek

New Member
Joined
Jun 1, 2017
Messages
1
Hello,

We have a spreadsheet that has information from our PO's. I would like to be able to group all the item numbers into one cell with this symbol | in-between with no spaces. Thank you for your help!

Tony

With spreadsheet below, I would like to know how to put in a formula to create
70187|70170C|70008|70224|70009|70122|70117|70118
Customer NameDoc. No.Product #Qty.UnitsPoundsReq. Del. Date
A271197018720CASE8006/1/2017
B2711970170C2CASE406/1/2017
C271197000835CASE4206/1/2017
D27119702245CASE606/1/2017
E271197000940CASE4806/1/2017
F271197012255CASE6606/1/2017
G271197011780CASE9606/1/2017
H271197011840CASE4806/1/2017
<colgroup><col width="100" style="width: 75pt; mso-width-source: userset; mso-width-alt: 3657;"> <col width="64" style="width: 48pt;"> <col width="53" style="width: 40pt; mso-width-source: userset; mso-width-alt: 1938;"> <col width="64" style="width: 48pt;" span="4"> <tbody> </tbody>
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
tbednarek,

Welcome to the MrExcel forum.

I know that you asked for a formula solution, but, none of the Formula Gurus have responded.

Here is a macro solution for you to consider that will run in the active worksheet.

I assume that your raw data is grouped by Doc. No. in column B .


Sample raw data, and, results, in the active worksheet:


Excel 2007
ABCDEFGH
1Customer NameDoc. No.Product #Qty.UnitsPoundsReq. Del. Date
2A271197018720CASE8006/1/201770187|70170C|70008|70224|70009|70122|70117|70118
3B2711970170C2CASE406/1/2017
4C271197000835CASE4206/1/2017
5D27119702245CASE606/1/2017
6E271197000940CASE4806/1/2017
7F271197012255CASE6606/1/2017
8G271197011780CASE9606/1/2017
9H271197011840CASE4806/1/2017
10
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub JoinProductNumbers()
' hiker95, 06/02/2017, ME1007986
Dim lr As Long, lc As Long, r As Long, n As Long
Application.ScreenUpdating = False
With ActiveSheet
  lr = .Cells(Rows.Count, 2).End(xlUp).Row
  lc = .Cells(1, Columns.Count).End(xlToLeft).Column
  For r = 2 To lr
    n = Application.CountIf(.Columns(2), .Cells(r, 2).Value)
    If n > 1 Then
      .Cells(r, lc + 1) = Join(Application.Transpose(.Range("C" & r & ":C" & (r + n) - 1)), "|")
    End If
    r = r + n - 1
  Next r
  .Columns(lc + 1).AutoFit
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Then run the JoinProductNumbers macro.
 
Upvote 0
tbednarek,

Here is an updated macro, just in case the information in column B only has one Doc. No..

New sample raw data, and, results, in the active worksheet:


Excel 2007
ABCDEFGH
1Customer NameDoc. No.Product #Qty.UnitsPoundsReq. Del. Date
2A271197018720CASE8006/1/201770187|70170C|70008|70224|70009|70122|70117|70118
3B2711970170C2CASE406/1/2017
4C271197000835CASE4206/1/2017
5D27119702245CASE606/1/2017
6E271197000940CASE4806/1/2017
7F271197012255CASE6606/1/2017
8G271197011780CASE9606/1/2017
9H271197011840CASE4806/1/2017
103333377777777777777
11
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Code:
Sub JoinProductNumbers_V2()
' hiker95, 06/02/2017, ME1007986
Dim lr As Long, lc As Long, r As Long, n As Long
Application.ScreenUpdating = False
With ActiveSheet
  lr = .Cells(Rows.Count, 2).End(xlUp).Row
  lc = .Cells(1, Columns.Count).End(xlToLeft).Column
  For r = 2 To lr
    n = Application.CountIf(.Columns(2), .Cells(r, 2).Value)
    If n = 1 Then
      .Cells(r, lc + 1) = .Range("C" & r)
    ElseIf n > 1 Then
      .Cells(r, lc + 1) = Join(Application.Transpose(.Range("C" & r & ":C" & (r + n) - 1)), "|")
    End If
    r = r + n - 1
  Next r
  .Columns(lc + 1).AutoFit
End With
Application.ScreenUpdating = True
End Sub

With the same instructions as my last reply.

Then run the JoinProductNumbers_V2 macro.
 
Upvote 0
tbednarek,

Welcome to the Board.

With spreadsheet below, I would like to know how to put in a formula to create
70187|70170C|70008|70224|70009|70122|70117|70118

If you're using Excel 2016 (which I'm not), you have access to the function TEXTJOIN:

"The TEXTJOIN function combines the text from multiple ranges and/or strings, and includes a delimiter you specify between each text value that will be combined. If the delimiter is an empty text string, this function will effectively concatenate the ranges."

If you're using a version prior to Excel 2016, you can step through the following process to create a pseudo-array formula:


  1. Select cell H1.
  2. Type =TRANSPOSE(C2:C9)&"|" in formula bar.
  3. Press F9.
  4. Delete curly brackets in formula bar.
  5. Delete last delimiting character.
  6. Type =Concatenate( in front of all characters in formula bar.
  7. Type ) after last character in formula bar.
  8. Press Enter

Cheers,

tonyyy
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,672
Messages
6,161,198
Members
451,688
Latest member
Gregs44132

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