merge multiple rows- is this possible

mrxwanttobe

New Member
Joined
Apr 27, 2018
Messages
23
Office Version
  1. 2007
Platform
  1. Windows
hello all. someone sent me a comma delimited file. Each complete customer record ends with the line that starts with the word Tax. Is there a way to move that data to one row of comma separated values?

Example in first record would be 1,CANCUN AUTO REPAIR,7110 LINDEN AVE,,ROSEMONT,IL,773 981-8014,,MARTIN,,(fax),(Rep),AreaDES,,(lob),,(Crlim 0),,(Tax Cde2),, and then the next record.

CustomerName and Address
1​
CANCUN AUTO REPAIR
7110 LINDEN AVE
ROSEMONTIL"
773-981-8014
MARTIN
(Fax )"(Rep )
(Area DES)
(Lob )
(CrLim 0)
(Tax Cde 2)"
501​
O'REILLY AUTO PART
5010 W. NORTH AVE
CHICAGOIL 60639"
773 622 7068
(Fax )"(Rep )
(Area BEL)
(Lob )
(CrLim 0)
(Tax Cde 3)"
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
try this:
VBA Code:
Sub test()
Dim outarr()
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
inarr = Range(Cells(1, 1), Cells(lastrow, 2))
indi = 2
maxcol = 1
colno = 1
ReDim outarr(1 To lastrow, 1 To 50) As Variant
For i = 2 To lastrow
  For j = 1 To 2
   If Left(inarr(i, j), 4) = "(Tax" Then
    outarr(indi, colno) = inarr(i, j)
    indi = indi + 1
    colno = 1
   Else
   outarr(indi, colno) = inarr(i, j)
   colno = colno + 1
   If colno > maxcol Then
    maxcol = colno
   End If
   End If
 Next j
Next i
With Worksheets("Sheet2")
 .Range(.Cells(1, 1), .Cells(indi, maxcol)) = outarr
 End With

End Sub
I have assumed that there are never more than 50 columns needed, this could be changed very easily
do you want to get rid of the blanks too, that is very easily done too
 
Upvote 0
Solution

Forum statistics

Threads
1,214,983
Messages
6,122,591
Members
449,089
Latest member
Motoracer88

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