Excel 2016,获取包含特定值的所有列 headers

Excel 2016, Getting all column headers that contain a certain Value

我有一个 excel sheet,其中有很多列,每个列都有一个唯一的 header 这些列包含日期

我需要制作一份报告(如 Pivot table),以获取指定日期 header 的所有列

我试图在这里举一个例子,但我做不到所以我在下面包含了一个示例工作簿,我还添加了一个描述数据构建方式的屏幕截图

屏幕截图:

Example Workbook

我需要的是一个像 pivot table 一样的报告,例如,如果我选择 2019 年 4 月,给我包含这个值 [=14] 的所有列 Headers =]

我知道在原始数据中,如果我为每个日期创建一个新行,并且只为该类型创建一列,我可以使数据透视表 table 起作用

我想问问有没有办法解决这个问题

提前致谢

像下面这样的东西会搜索稳定性 Sheet 并将所有找到的列 headers 放在 Sheet 报告的 B 列中,只要您输入要搜索的日期报告 A1:

Sub foo()
Dim ws As Worksheet: Set ws = Sheets("Stability")
Dim wsReport As Worksheet: Set wsReport = Sheets("Report")
'declare and set your worksheet, amend as required
icounter = 0
X = Format(wsReport.Cells(1, 1).Value, "dd.mmm.yyyy")
'above enter value to search for in Sheet Report A1
Set valuefound = ws.Range("AG3:BI5000").Find(What:=X, LookIn:=xlValues)
'above look for value X in column B
If Not valuefound Is Nothing Then 'if found then
    foundaddress = valuefound.Address 'save the address of the first instance found
    LastRow = wsReport.Cells(wsReport.Rows.Count, "B").End(xlUp).Row + 1
    wsReport.Cells(LastRow, 2).Value = ws.Cells(2, valuefound.Column)
    FoundAt = ws.Cells(2, valuefound.Column)
    Do
        Set valuefound = ws.Range("AG3:BI5000").FindNext(valuefound) 'find next value
        LastRow = wsReport.Cells(wsReport.Rows.Count, "B").End(xlUp).Row + 1
        wsReport.Cells(LastRow, 2).Value = ws.Cells(2, valuefound.Column)
    Loop While Not valuefound Is Nothing And valuefound.Address <> foundaddress
End If
End Sub