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