0

我希望我的宏能够在特定行中搜索相关文本,以便它只搜索该行而不搜索其他行。例如,当您输入“dave”时,它应该只在 E 行中搜索“dave”。

Dim Answer, Reply
Dim b As Range

Answer = Application.InputBox("Enter the text to search for.", "Search Tool")

With Rows

  Set c = .Find(Answer, LookIn:=xlValues)

    If Not c Is Nothing Then
        firstAddress = c.Address
          Do
          Reply = MsgBox("Has this piece been edited? " & c.Address & _
          " which has a value of " & c.Value & "?", vbQuestion + _
          vbYesNoCancel, "Cell Hi-Liter")

            If Reply = vbYes Then
             c.Select
             Selection.Copy
             Selection.Offset(0, 1).Select
             ActiveSheet.Paste
             Exit Do
            End If

             Set c = .FindNext(c)
             Loop While Not c Is Nothing And c.Address <> firstAddress

                Else
                   MsgBox "Your search text was not found.", vbOKOnly, "Text Not Found"
      End If

End With


End Sub

我怎样才能做到这一点?

4

1 回答 1

1

如果您要在 E 列中查找“Dave”,请使用以下代码。此代码仅供参考。如果它在 E 列中找到 Dave,它会在 F 列中输入确认信息。

Sub FindDave()
    Dim rngToFind As Range

    Set rngToFind = ActiveSheet.Columns("E:E")

    Dim c As Range
    Dim firstAddress As String

    With rngToFind
        Set c = .Find("Dave", LookIn:=xlValues)
        If Not c Is Nothing Then
            firstAddress = c.Address
            Do
                c.Offset(0, 1).Value = "Found on my left"
                Set c = .FindNext(c)
            Loop While Not c Is Nothing And c.Address <> firstAddress
        End If
    End With

End Sub

如果您不希望在特定列中找到“Dave”,请务必让我们知道您要查找的确切位置。

希望这可以帮助。维卡斯 B

于 2013-08-02T11:10:08.167 回答