[英]Excel VBA find a cell on worksheet with specific value (string)
I need help finding a text value on a worksheet and offset from there two rows down. 我需要在工作表上查找文本值并从那里向下偏移两行的帮助。
I have a cell with "Bottom of Range" title in it. 我有一个带有“范围底部”标题的单元格。 Two cells below that is the actual value.
下方的两个单元格为实际值。 The issue is "Bottom of Range" could be in 7 possible places depending on the worksheet template.
问题是“范围底部”可能在7个可能的位置,具体取决于工作表模板。
How can I find the cell with "Bottom of Range" in it? 如何找到其中包含“范围底部”的单元格? I can then .Offset(2,0).value2 to get what I want.
然后,我可以.Offset(2,0).value2得到我想要的。
In the grander scheme of things. 在更宏大的计划中。 I am cycling through hundreds of workbooks and then through each of their worksheets collecting data and centralizing it.
我正在浏览数百本工作簿,然后遍历他们的每个工作表来收集数据并将其集中化。 Because the values I am looking for could be anywhere I need to look for their title/definition before getting to the values.
因为我要查找的值可能在任何地方,所以在获得这些值之前,我需要先查找它们的标题/定义。
Here you go! 干得好! You want to use .Find:
您要使用。查找:
Sub t()
Dim bottomCell As Range
Dim offsetCell As Range
With Sheets("Sheet1")
Set bottomCell = .Cells.Find(what:="Bottom of Range")
Set offsetCell = bottomCell.Offset(2, 0)
' Now, your offsetCell has been created as a range, so go forth young padawan!
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.