我有一个填充了Yes和No值的表。我需要一个公式,将所有单元格定位为“是”,并索引用于定义单元格的行(苹果,橙,梨)和列(Molly,Joe,Sarah)标题。
然后获取已定义的行和列信息,并将其放在第二个工作表上的两列中。
如果“是”或“否”值发生变化,我希望能够更新。
工作表1上的我的是/否表:
Molly Joe Sarah Apples Y N Y Orange N Y N Pear Y N N
我想在工作表2上看起来如何:
Column A Column B Molly Apples Molly Pear Joe Orange Sarah Apple
答案 0 :(得分:1)
这个答案只是扩展了DaveParillo在How to “unpivot” or “reverse pivot” in Excel?
给出的上述答案。答案 1 :(得分:0)
使用powerquery(来自Microsoft的免费Powerquery add-in获取和Transfom Data选项卡Excel 2016,2013 Powerquery选项卡),使用表名为Table2的表中的数据
M代码:
let
Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Molly", type text}, {"Joe", type text}, {"Sarah", type text}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Column1"}, "Attribute", "Value"),
#"Filtered Rows" = Table.SelectRows(#"Unpivoted Columns", each ([Value] = "Y")),
#"Reordered Columns" = Table.ReorderColumns(#"Filtered Rows",{"Attribute", "Column1", "Value"}),
#"Removed Columns" = Table.RemoveColumns(#"Reordered Columns",{"Value"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Attribute", "Column A"}, {"Column1", "Column B"}})
in
#"Renamed Columns"
<强>输入:强>
<强>输出:强>
<强>过程:强>
答案 2 :(得分:0)
Sub Main()
Dim cell As Range
Dim sht2 As Worksheet
Set sht2 = Worksheets("Sheet2")
With Worksheets("Sheet1").Range("A1").CurrentRegion
.Replace What:="Y", Replacement:="0", LookAt:=xlWhole
For Each cell in .SpecialCells(xlCellTypeConstants, xlNumbers)
sht2.Cells(Rows.Count, 1).End(xlUp).Offset(1).Value = cell.End(xlUp).Value
sht2.Cells(Rows.Count, 2).End(xlUp).Offset(1).Value = cell.End(xlToLeft).Value
Next
.Replace What:="0", Replacement:="Y", LookAt:=xlWhole
End With
End Sub