简体   繁体   English

使用VBA选择其中包含文本的单元格

[英]Using VBA to select a cell with text in it

How do I select a cell with "Part # 1" in it, and then use that cell as one of the parameters to select a range of cells. 如何选择其中包含“部件号1”的单元格,然后使用该单元格作为参数之一来选择一系列单元格。 For example: If "Part # 1" was in cell A1, I want to select a range of cells A1:D4. 例如:如果“ Part#1”位于单元格A1中,我想选择一个范围为A1:D4的单元格。

Sub Part_1_Select

'Seach for Cell somehow'
Cell.Activate
ActiveCell: D4.Select
Selection.Copy
Range("B4").Select
Selection.Paste
End Sub

This is what I'm thinking it should be similar too. 这就是我想也应该类似的内容。

For Each c In Worksheets("Sheet1").Range("A1:D10").Cells
    If c.Value = "Part # 1" Then
       Cell.Activate
       Range(c & ":D4").Select
    End If
Next

This isn't perfect code but it may provide you with a good starting point to get where you want. 这不是完美的代码,但是它可能为您提供一个到达所需位置的良好起点。

    Range(Cells.Find(What:="Part # 1").Address & ":D4").Select

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM