根据excel中单元格的值获取整行

搜寻者

我试图根据任何单元格的值获取一整行数据,其范围从E到BH。例如,如果我在单元格P,3上具有值“红色”,我想选择从E3到BH,3的整个范围。

另外,如果我在F9中的某个单元格上具有“ Yellow”值,则我想选择从E9到BH9的整个行

到目前为止,我已经尝试过什么这是我尝试从字符串“我的文本”中获取行,但是它不起作用。我计划以与获取行和列类似的方式获取行和列,以便根据文本获取行从e(row)到bh(row)

Dim rng1 As Range
Set rng1 = Sheets("Table").UsedRange.Find("my text", xlValues, xlWhole)
Debug.Print "row is: " & rng1
大本钟

也许使用IntersectEntireRow请注意,您还应该测试是否Find成功使用If Not rng1 Is Nothing

Set rng1 = Sheets("Table").UsedRange.Find(What:="my text", LookIn:=xlValues, LookAt:=xlWhole)

If Not rng1 Is Nothing Then
    Dim theNewRange As Range
    Set theNewRange = Intersect(rng1.EntireRow, Range("E:BH"))
End If

使用rng1.Row以下更短的替代方法

If Not rng1 Is Nothing Then
    Dim theNewRange As Range
    Set theNewRange = Range("E:BH").Rows(rng1.Row)
End If

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章