托尼已经给你一种方法。这是另一个使用通配符。现在,使用通配符,因为假设你有细胞是非常重要的,其中
A1 =含税
B10 =含税&费
C15 =含税& FEE1
D20 = 123Tax
G45 = DoggyTax
如果你只是想寻找税*即税单,缴税&手续费和税金&费用1?
而且当你正在做的所有细胞中的搜索,那么你必须指定范围。这里是快速示例
Option Explicit
Sub Sample()
Dim oRange As Range, aCell As Range, bCell As Range
Dim ws As Worksheet
Dim ExitLoop As Boolean
Dim SearchString As String, FoundAt As String
On Error GoTo Err
'~~> The Sheet where the search has to be performed
Set ws = Worksheets("Sheet1")
'~~> In All cells
Set oRange = ws.Cells
'~~> Search string
SearchString = "Tax*"
Set aCell = oRange.Find(What:=SearchString, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
'~~> If search was found
If Not aCell Is Nothing Then
Set bCell = aCell
FoundAt = aCell.Address
Do While ExitLoop = False
Set aCell = oRange.FindNext(After:=aCell)
If Not aCell Is Nothing Then
If aCell.Address = bCell.Address Then Exit Do
FoundAt = FoundAt & ", " & aCell.Address
Else
ExitLoop = True
End If
Loop
Else
MsgBox SearchString & " not Found"
End If
MsgBox "The Search String has been found these locations: " & FoundAt
Exit Sub
Err:
MsgBox Err.Description
End Sub
您可以在下面提到的链接中找到更多关于FIND()和FINDNEXT()的信息。
话题:.Find和.FindNext在Excel VBA
LINK:http://siddharthrout.wordpress.com/2011/07/14/find-and-findnext-in-excel-vba/
注意:如果你想找到的 “税” 的所有实例,那么你不需要通配符。所有你需要做的就是按照Tony的建议使用下面的内容。
LookAt:=xlPart
HTH
希德
+1在第一去工作! :) – 2012-02-21 03:18:11