Excel使用公式/宏重构

时间:2015-12-11 12:53:57

标签: excel

我有一个excel表,看起来像这样:

enter image description here

我需要能够像这样自动重新格式化:

enter image description here

我已经尝试了所有可能的公式,以及每个可能的数据透视表的变化,但却无法找到任何甚至远程让我到达我想要的地方。例如,在其他列中添加Vlookup然后生成4个表并进行合并太过手动,无法使用。尝试使用索引/匹配,这也没有解决,因为它太手动。在现实生活中,这个表的大小会有所不同,所以调整"重新格式化"表不是最佳的。 任何想法,建议都非常欢迎!

2 个答案:

答案 0 :(得分:1)

使用以下数据:

enter image description here

这个简短的宏:

Sub ReOrganizeData()
Dim i As Long, j As Long, K As Long, N As Long
Dim v As Variant

N = Cells(Rows.Count, "A").End(xlUp).Row
K = 2
For j = 2 To 5
   For i = 3 To N
      v = Cells(i, j)
      If v <> "" Then
         Cells(K, "H") = Cells(i, "A")
         Cells(K, "I") = v
         Cells(K, "J") = Cells(2, j)
         K = K + 1
      End If
   Next i
Next j
End Sub

将产生:

enter image description here

答案 1 :(得分:0)

可能基本上是详细的过程here。但是在您的情况下,您需要在结果表中切换val v = for { nestedMap <- map("Hello") value <- nestedMap("world") } yield value Column的顺序,转换为范围以便能够对列中的行进行排序,并过滤以从中选择和删除空白行Value。您还需要更改列标签。

相关问题