返回
化繁为简,逆转透视数据,Excel妙招大放送
Excel技巧
2023-12-24 01:03:15
我们时常会遇到这样的表格:同一个部门的人员名单挤在同一个单元格内。当我们需要把这些数据转换成数据列表时,该怎么办呢?别担心,Excel有多种方法可以实现这一操作,赶快学起来吧!
方法一:使用“复制”和“粘贴”
-
首先,在透视表中选择要转换的数据区域。
-
然后,按住“Ctrl+C”组合键将数据复制到剪贴板。
-
接着,打开一个新的工作表,然后按住“Ctrl+V”组合键将数据粘贴到新的工作表中。
-
最后,使用“文本转列向导”将数据转换为数据列表。
方法二:使用“透视表选项”
-
首先,单击透视表的任意一个单元格。
-
然后,单击“选项”选项卡,然后单击“透视表选项”按钮。
-
在“透视表选项”对话框中,单击“数据”选项卡。
-
然后,选中“在源数据中显示摘要数据”复选框。
-
最后,单击“确定”按钮。
这样,透视表中的数据就会显示在源数据中。
方法三:使用VBA代码
如果要转换的数据量很大,可以使用VBA代码来实现。
Sub ReversePivotTable()
Dim pt As PivotTable
Dim ws As Worksheet
Dim rng As Range
Dim i As Long, j As Long
'Get the active pivot table
Set pt = ActiveSheet.PivotTables(1)
'Get the data range of the pivot table
Set rng = pt.TableRange2
'Get the worksheet that contains the pivot table
Set ws = pt.Parent
'Loop through the rows of the data range
For i = 2 To rng.Rows.Count
'Loop through the columns of the data range
For j = 1 To rng.Columns.Count
'Get the value of the cell
strValue = rng.Cells(i, j).Value
'Split the value into an array of values
aryValues = Split(strValue, ",")
'Loop through the array of values
For k = 0 To UBound(aryValues)
'Insert the value into the worksheet
ws.Cells(i, j + k).Value = aryValues(k)
Next k
Next j
Next i
'Delete the pivot table
pt.Delete
End Sub
将此代码粘贴到VBA编辑器中,然后运行它。这样,透视表中的数据就会显示在源数据中。
总结
以上就是几种将透视表数据转回数据列表的方法。您可以根据自己的需要选择合适的方法。