Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 如何在整个工作表中查找包含字符串的单元格_Vba_Excel - Fatal编程技术网

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

Vba 如何在整个工作表中查找包含字符串的单元格,vba,excel,Vba,Excel,我想在工作表中找到包含特定字符串的单元格 我不知道电子表格中将有多少列或行,因此我想用CurrentRegion来做这件事 这就是我所尝试的: =FIND("Data String", Range("A1").CurrentRegion) 您应该查看Microsoft引用: 例如: Dim rngFound as Range With Worksheets("MySheetName").Cells Set rngFound = .Find("MySearchString", Look

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

我不知道电子表格中将有多少列或行,因此我想用
CurrentRegion
来做这件事

这就是我所尝试的:

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

您应该查看Microsoft引用:

例如:

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

搜索整个工作表

您应该查看Microsoft参考资料:

例如:

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
搜索整个工作表

试试这个

 FindString = Sheets("Sheet1").Range("D1").Value
----------这将使用
输入框
值选择范围内的下一个
单元格

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
Sub Find_First()
作为字符串的暗FindString
变暗Rng As范围
FindString=InputBox(“输入搜索值”)
如果修剪(FindString)“,则
带活页(“活页1”)。范围(“A:A”)
Set Rng=.Find(What:=FindString_
之后:=.Cells(.Cells.Count)_
LookIn:=xlValues_
看:=xlother_
搜索顺序:=xlByRows_
SearchDirection:=xlNext_
匹配案例:=假)
如果不是,那么Rng什么都不是
应用程序。转到Rng,对
其他的
MsgBox“未找到任何内容”
如果结束
以
如果结束
端接头
试试这个

 FindString = Sheets("Sheet1").Range("D1").Value
----------这将使用
输入框
值选择范围内的下一个
单元格

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
Sub Find_First()
作为字符串的暗FindString
变暗Rng As范围
FindString=InputBox(“输入搜索值”)
如果修剪(FindString)“,则
带活页(“活页1”)。范围(“A:A”)
Set Rng=.Find(What:=FindString_
之后:=.Cells(.Cells.Count)_
LookIn:=xlValues_
看:=xlother_
搜索顺序:=xlByRows_
SearchDirection:=xlNext_
匹配案例:=假)
如果不是,那么Rng什么都不是
应用程序。转到Rng,对
其他的
MsgBox“未找到任何内容”
如果结束
以
如果结束
端接头

.address将显示单元格,按f1键进行查找,它将显示帮助和返回的内容,小心返回
nothing
而不是
range
您将Excel函数
FIND
和VBA
range
方法
FIND
混为一谈。你想用哪一个?(希望是
Range.Find
方法。Excel函数对您没有帮助。)。address将显示单元格,按f1键进行查找,然后显示帮助和返回的内容,小心返回
nothing
而不是
range
您将Excel函数
FIND
和VBA
range
方法
FIND
混为一谈。你想用哪一个?(希望
Range.Find
方法。Excel函数对您没有帮助。)告诉我它是否对您有帮助谢谢,是的,它确实有帮助,我将在我的一些子程序中使用Set Rng。谢谢!告诉我它是否对你有帮助Hanks,是的,它肯定有,我会在我的一些子程序中使用Set Rng。谢谢!杰出的非常感谢!非常感谢你