简体   繁体   中英

How to make one row from zig zag data in excel

I recently encountered a problem while establishing data structure in Excel.

The format that I need to handle is having the forms below.

1   3   5   7   9    
2   4   6   8   10

The data is taking up two rows moving up and down.

I would like to rearrange those data in a one row as below.

1   2   3   4   5   6   7   8   9   10

What function do I need to use in Excel?

I tried to just copy and paste or '=' command only. However the amount of data that i need to handle is too big to do it manually. Please help..

Thanks in advance.

Put this in a cell and drag it right.

=INDEX($A$1:$E$2, MOD(COLUMN(A:A)-1, 2)+1, (COLUMN(A:A)-1)/2+1)

在此输入图像描述

I would use vba, as this would require an iteration. This works only if both the two "zig-zag" rows are in the first and second rows of the sheet row (A) and row (B) respectively.

Sub combine()
Dim wb As Workbook
Dim ws As Worksheet
Dim i As Long
Dim j As Long
Dim k As Long
Dim LastCol As Long

Set wb = ActiveWorkbook
Set ws = wb.ActiveSheet
j = 4
k = 1
 LastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
 With ws


  For i = 1 To LastCol
     .Cells(j, k).Value = .Cells(1, i).Value
     k = k + 1
     .Cells(j, k).Value = .Cells(2, i).Value
     k = k + 1
  Next i

 End With
 End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM