You are here:

Excel/Transposing multiple colums with alternating data


Hello, I am having some trouble trying to figure out how to do this.

My data starts in A1 below

012620 313035 15-52-A-01
012620 318515 20-15-A-01
012620 326003 20-20-A-02
014202 313061 15-49-A-02
014202 318498 20-27-B-01

But I need to move all the like items from A1 to a single row, alternating B1 and C1 until the next group of different number in A1 like below.

012620 313035 15-52-A-01 318515 20-15-A-01 326003 20-20-A-02
014202 313061 15-49-A-02 318498 20-27-B-01

Any help would be appreciated thanks.


Make a copy of your sheet with the data and run this macro against the copy:

Sub ABC()
Dim s As String, i As Long, j As Long
Dim col As Long
s = Left(Cells(1, "A").Value, 6)
i = 1
For j = 2 To Cells(Rows.Count, "A").End(xlUp).Row
 If Cells(j, 1) Like s & "*" Then
   col = Cells(i, Columns.Count).End(xlToLeft).Column + 1
   Cells(i, col).Value = Cells(j, "A").Value
   Cells(j, "A").ClearContents
   s = Left(Cells(j, 1), 6)
   i = i + 1
   Cells(i, "A").Value = Cells(j, "A").Value
   Cells(j, "A").ClearContents
 End If
End Sub

For your data you posted, that produced the results you show.

Tom Ogilvy  
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts


Tom Ogilvy


Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]


Extensive experience.

Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2017 All rights reserved.