You are here:

Excel/macro to convert 2 columns into 1 column

Advertisement


Question
Hi Jan.
I am trying to create a simple macro that converts 2 columns of data into one column of data
e.g.
from
1 A
2 B
3 C
4 D
5 E

to
1
A
2
B
3
C
4
D
5
E
the macro just keeps running until the end of the data in the 2 columns

Answer
Hi Tom,

This little macro does the trick:

Sub processData()
   Dim lCt As Long
   lCt = 1
   Do While Cells(lCt, 1).Value <> ""
       If Cells(lCt, 2).Value <> "" Then
         Cells(lCt + 1, 1).EntireRow.Insert
         Cells(lCt + 1, 1).Value = Cells(lCt, 2).Value
         Cells(lCt, 2).ClearContents
       End If
       lCt = lCt + 2
   Loop
End Sub
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

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Jan Karel Pieterse

Expertise

Excel and Excel/VBA questions

Experience

Excel MVP

Organizations
Self employed Excel developer

Education/Credentials
Bachelor in Chemical Engineering

Awards and Honors
Microsoft MVP award since 2002

Past/Present Clients
Shell, Fortis bank, ABN-AMRO bank, Morgan Stanley, ...

©2016 About.com. All rights reserved.