[英]Excel - how to match a column header with a row header (dates) and return a lookup value in VBA
I've looked high and low for this and can't find a solution. 我为此寻找高低,找不到解决方案。 Plenty with formulas, but it must be in VBA. 有很多公式,但是必须在VBA中。
I have a range of text in column A (A2:A100) and dates in column B (B2:B100), with sequential calendar dates in row 1 (C1:Z1). 我在A列(A2:A100)中有一系列文本,在B列(B2:B100)中有日期,在第1行(C1:Z1)中有连续的日历日期。 For every cell in the matrix/table, if the date in column B is the same as the date in row 1, the text in corresponding column A must be displayed. 对于矩阵/表中的每个单元格,如果B列中的日期与第1行中的日期相同,则必须显示相应A列中的文本。 I can't use a VLOOKUP or MATCH formula, as the columns are narrow and don't display the full text unwrapped because of the formula in the adjacent cell. 我不能使用VLOOKUP或MATCH公式,因为列很窄,并且由于相邻单元格中的公式而无法显示展开的全文。 Thanks for any guidance. 感谢您的指导。 In the below, N2 must be "Electrician chasing", since N1 is the same as B2. 在下面,由于N1与B2相同,因此N2必须是“电工追赶”。
I think you want this (and you got your columns A and B the wrong way round) 我认为您想要这样做(并且您以错误的方式获得了A列和B列)
Sub LoopAndDisplay
Dim r as range
For each r in range("C2:Z200")
If cells(1,r.column) = cells(r.row,2) then 'if date above matches column B then
r = cells(r.row,1) 'display contents of column A
End If
Next R
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.