Excel数据格式

我正在努力格式化下表。 目标是从表1到表2.下面的图像提供了一个大型数据集的样本。 你如何转置表1并转换为表2? 谢谢。 在这里输入图像说明

你不是转置数据(翻转X = -y对angular线的数据); 您将二维范围转换为一维范围。

另外,这里已经回答了这个问题:

我想你想要的是不透明的。 这实际上是在Excel 2013本机,但以前的版本,你必须破解自己的版本。 以下是一些基于您的示例数据的基本示例。 如果您进行微调,以适应您的实际距离位置,这应该为您带来90%的路程。

Sub Unpivot() Dim headerRow, row, newRow, col As Integer Dim ws1, ws2 As Worksheet Set ws1 = Sheets(1) Set ws2 = Sheets(2) headerRow = 2 row = 4 newRow = 4 While ws1.Cells(row, 1).Value <> "" col = 5 While (ws1.Cells(headerRow, col) <> "") ws2.Range("A" & newRow & ":D" & newRow).Value = _ ws1.Range("A" & row & ":D" & row).Value ws2.Cells(newRow, 5).Value = ws1.Cells(headerRow, col).Value ws2.Cells(newRow, 6).Value = ws1.Cells(row, col).Value newRow = newRow + 1 col = col + 1 Wend row = row + 1 Wend End Sub 

示例input,包含行和列:

在这里输入图像说明

示例输出:

在这里输入图像说明