![](/img/trans.png)
[英]Excel VBA Select a Range of Cells Until a Cell Contains Specific Text
[英]Select range until cell with certain text in Excel with VBA
尝试选择标题/第一行及其下的数据(从C列到O列),直到C列的第一个单元格带有单词“ Estimated”,我才根据另一个关于stackoverflow的答案提出了VBA代码,但似乎没有正在工作
感谢所有帮助!!
Range("C1").Select
For i = 1 To 9999
If ISNUMBER(SEARCH(ActiveCell.Offset(0, i), "Estimated")) = TRUE Then Exit For
If ISNUMBER(SEARCH(ActiveCell.Offset(0, i), "Estimated")) = FALSE Then Exit For
Next
If ISNUMBER(SEARCH(ActiveCell.Offset(0, i), "Estimated")) = TRUE Then
Range(Cells(ActiveCell.Row, 15), Cells(ActiveCell.Row, ActiveCell.Column + i - 1)).Select
`
尝试,
range(cells(1, "C"), cells(application.match("Estimated", columns(3), 0)-1, "O")).select
从您的叙述中不确定是否包含“估计”的行。 -1
告诉它不包括“估计”行。
你可以用
Range("O1", Columns(3).Find("Estimated", , xlValues, xlPart)).Select ' to include row with "Estimated" in column C
要么
Range("O1", Columns(3).Find("Estimated", , xlValues, xlPart).offset(-1)).Select ' to exclude row with "Estimated" in column C
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.