从列行匹配中创build列表

我有一个表的第一行是列标题,第一列是行标签。 我已经在这些匹配的每个单元格中放入TRUE

我需要在每个列的单独表格中生成一个列表,其中只包含与单元格为TRUE的匹配行名称。

因此,如果sheet1中的B13B15C12TRUE ,则sheet2将显示列B ,其下面是1315 ,列C位于它下面。 除了使用我input的标签,而不是字母和数字。

我还没有设法绕过我的头从这个开始,所以任何指针在正确的方向表示赞赏。

我已经尝试为列标题和行标签创build一个定义的名称。

我不完全理解你的表的布局,但假设它看起来像我testing的下面的例子,这个VBA应该工作。

Sheet1表格格式

在这里输入图像说明

Sheet2输出结果

在这里输入图像说明

VBA

 Sub test() Dim i As Long Dim j As Long Dim lRow As Long Dim lCol As Long Dim ws1 As Worksheet Dim ws2 As Worksheet Set ws1 = Sheets("Sheet1") Set ws2 = Sheets("Sheet2") lRow = ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row lCol = ws1.Cells(1, ws1.Columns.Count).End(xlToLeft).Column With ws1 For j = 2 To lCol ws2.Cells(1, j).Value = .Cells(1, j).Value For i = 2 To lRow If .Cells(i, j).Value = True Then ws2.Cells(ws2.Rows.Count, j).End(xlUp).Offset(1, 0).Value = .Cells(i, 1).Value 'This will probably need to be changed to 'i' to represent the row number for your purposes End If Next i Next j End With End Sub