我想在包含特定字符串的工作表中找到单元格。如何在整个工作表中找到包含字符串的单元格
我不知道电子表格中会有多少列或行,因此我想用CurrentRegion
来做。
这就是我努力:
=FIND("Data String", Range("A1").CurrentRegion)
我想在包含特定字符串的工作表中找到单元格。如何在整个工作表中找到包含字符串的单元格
我不知道电子表格中会有多少列或行,因此我想用CurrentRegion
来做。
这就是我努力:
=FIND("Data String", Range("A1").CurrentRegion)
你应该看看到Microsoft参考文献:Range.Find Method (Excel)。
.Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte, SearchFormat)
实施例:
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
搜索整个片
非常好!非常感谢 – Porkball21
尝试这个
FindString = Sheets("Sheet1").Range("D1").Value
----------这将选择下一个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
告诉我它是否帮助你 – shakespeare
谢谢,是的,它肯定有,我会在一些子例程中使用Set Rng。非常感谢! – Porkball21
。地址会显示该单元格,按F1 FIND,它会告诉你,然后帮助和它返回什么,小心的'nothing'返回,而不是'range' –
你是将Excel函数'FIND'和VBA'Range'方法'Find'混合起来。你想使用哪一个? (希望'Range.Find'方法.Excel函数不会帮助你。) – YowE3K