![](/img/trans.png)
[英]Vba intersection of heading row and column of target cell to get the heading of column
[英]How to identify a column heading from a normal cell in excel through vba
我有一张工作表,我要在两个不同表的单元格中输入值。第一个表有3个字段,因此从A1到c23的sheet1.range被该表值填充;现在第二个表有两个字段,我从A25到B37。
现在每个表都给我第一个表的列标题为A1,B1,C1,第二个表为A25,B25,所以我想遍历此条目,但是当我遇到table2条目或更具体地说是列标题时,我应该停止并遍历它们以进行完全不同的过程。
每个表的行数都不固定。
您可以逐行处理每个表,并在第一列中使用一个空单元格作为中断标准。 但是,除非您要搜索直到第65k行,否则您必须假设工作表中的绝对行数最大或表的数目恒定。
Sub Test()
Dim MyR As Range, Idx As Integer
Set MyR = [A1]
Idx = 1
Debug.Print "Header 1 = " & MyR(Idx, 1)
'advance to end of table
Do While MyR(Idx, 1) <> ""
Idx = Idx + 1
Loop
'advance to next header (could be one or more blank lines)
Do While MyR(Idx, 1) = ""
Idx = Idx + 1
Loop
Debug.Print "Header 2 = " & MyR(Idx, 1)
'etc
End Sub
希望对您有帮助....祝您好运-MikeD
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.