ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   how do you interleave two columns (https://www.excelbanter.com/excel-discussion-misc-queries/146205-how-do-you-interleave-two-columns.html)

bobbe

how do you interleave two columns
 
If you have two columns of data, what's the easiest way to automatically
(programatically?) interleave them. The resulting column should consist of:

1st cell of 1st column
1st cell of 2nd column
2nd cell of 1st column
2nd cell of 2nd column
etc.

For example,
1 a
2 b
3 c

would become:

1
a
2
b
3
c

ExcelBanter AI

Answer: how do you interleave two columns
 
To interleave two columns in Microsoft Excel, follow these steps:
[list=1][*]Open your Excel worksheet and select a blank cell where you want to start the interleaved data.[*]In the formula bar, type the following formula:
Code:

=IFERROR(INDEX(A:A,ROW()/2),INDEX(B:B,(ROW()+1)/2))
[*]Press Enter to apply the formula to the selected cell.[*]Copy the formula down to the rest of the cells in the column.[*]The resulting column will now consist of the interleaved data from the two columns.

Note: In the formula, "A:A" and "B:B" refer to the two columns of data you want to interleave. If your data is in different columns, you will need to adjust the formula accordingly. Also, if your data starts in a different row, you will need to adjust the formula to start at the correct row.

Toppers

how do you interleave two columns
 
In your selected column (say C), assuming data starts in row 1

in C1: =INDIRECT("A"&INT(ROW()/2)+1)
in C2: =INDIRECT("B"&ROW()/2)

Higlight both and copy down

Copy & Paste Special==Values if required

HTH

"bobbe" wrote:

If you have two columns of data, what's the easiest way to automatically
(programatically?) interleave them. The resulting column should consist of:

1st cell of 1st column
1st cell of 2nd column
2nd cell of 1st column
2nd cell of 2nd column
etc.

For example,
1 a
2 b
3 c

would become:

1
a
2
b
3
c


Gord Dibben

how do you interleave two columns
 
Sub columnmerge()

For i = 1 To 250
ActiveSheet.Cells(i, 3) = ActiveSheet.Cells _
((i + 1 - ((i + 1) Mod 2)) / 2, ((i + 1) Mod 2) + 1)
Next i

End Sub


Gord Dibben MS Excel MVP

On Tue, 12 Jun 2007 11:37:01 -0700, bobbe
wrote:

If you have two columns of data, what's the easiest way to automatically
(programatically?) interleave them. The resulting column should consist of:

1st cell of 1st column
1st cell of 2nd column
2nd cell of 1st column
2nd cell of 2nd column
etc.

For example,
1 a
2 b
3 c

would become:

1
a
2
b
3
c



bobbe

how do you interleave two columns
 
Thanks. Instead of 250 how do you get the number of cells in column A or B?
Some kind of length function?

"Gord Dibben" wrote:

Sub columnmerge()

For i = 1 To 250
ActiveSheet.Cells(i, 3) = ActiveSheet.Cells _
((i + 1 - ((i + 1) Mod 2)) / 2, ((i + 1) Mod 2) + 1)
Next i

End Sub


Gord Dibben MS Excel MVP

On Tue, 12 Jun 2007 11:37:01 -0700, bobbe
wrote:

If you have two columns of data, what's the easiest way to automatically
(programatically?) interleave them. The resulting column should consist of:

1st cell of 1st column
1st cell of 2nd column
2nd cell of 1st column
2nd cell of 2nd column
etc.

For example,
1 a
2 b
3 c

would become:

1
a
2
b
3
c




Gord Dibben

how do you interleave two columns
 
Sub columnmerge()
Dim Lrow As Long
Lrow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row

For i = 1 To Lrow * 2
ActiveSheet.Cells(i, 3) = ActiveSheet.Cells _
((i + 1 - ((i + 1) Mod 2)) / 2, ((i + 1) Mod 2) + 1)
Next i

End Sub


Gord

On Tue, 12 Jun 2007 14:16:01 -0700, bobbe
wrote:

Thanks. Instead of 250 how do you get the number of cells in column A or B?
Some kind of length function?

"Gord Dibben" wrote:

Sub columnmerge()

For i = 1 To 250
ActiveSheet.Cells(i, 3) = ActiveSheet.Cells _
((i + 1 - ((i + 1) Mod 2)) / 2, ((i + 1) Mod 2) + 1)
Next i

End Sub


Gord Dibben MS Excel MVP

On Tue, 12 Jun 2007 11:37:01 -0700, bobbe
wrote:

If you have two columns of data, what's the easiest way to automatically
(programatically?) interleave them. The resulting column should consist of:

1st cell of 1st column
1st cell of 2nd column
2nd cell of 1st column
2nd cell of 2nd column
etc.

For example,
1 a
2 b
3 c

would become:

1
a
2
b
3
c






All times are GMT +1. The time now is 10:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com