vba 如何在整个工作表中查找包含字符串的单元格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43654157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 12:31:56  来源:igfitidea点击:

How to find cell containing string in entire worksheet

excelvbaexcel-vba

提问by Porkball21

I would like to find a cell in a worksheet containing a specific string.

我想在包含特定字符串的工作表中找到一个单元格。

I won't know precisely how many columns or rows there will be in the spreadsheet, hence why I wanted to do it with CurrentRegion.

我不知道电子表格中有多少列或行,因此我想用CurrentRegion.

This is what I was trying:

这就是我正在尝试的:

=FIND("Data String", Range("A1").CurrentRegion)

回答by P??

You should have a look into the Microsoft References: Range.Find Method (Excel).

您应该查看 Microsoft References: Range.Find Method (Excel)

 .Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte, SearchFormat)

Example:

例子:

Dim rngFound as Range
With Worksheets("MySheetName").Cells
    Set rngFound  = .Find("MySearchString", LookIn:=xlValues)
    If Not rngFound Is Nothing Then 
        'something is found
    else
        'nothing found
    End If
End With

searches the whole sheet

搜索整个工作表

回答by shakespeare

Try This

尝试这个

 FindString = Sheets("Sheet1").Range("D1").Value

---------- This will select the next Cellin range with the inputboxvalue

---------- 这将选择Cell范围内的下一个inputbox

Sub Find_First()
Dim FindString As String
Dim Rng As Range
FindString = InputBox("Enter a Search value")
If Trim(FindString) <> "" Then
    With Sheets("Sheet1").Range("A:A")
        Set Rng = .Find(What:=FindString, _
                        After:=.Cells(.Cells.Count), _
                        LookIn:=xlValues, _
                        LookAt:=xlWhole, _
                        SearchOrder:=xlByRows, _
                        SearchDirection:=xlNext, _
                        MatchCase:=False)
        If Not Rng Is Nothing Then
            Application.Goto Rng, True
        Else
            MsgBox "Nothing found"
        End If
    End With
  End If
End Sub

Find Value

发现价值