【发布时间】:2014-09-11 20:11:08
【问题描述】:
下午
我有很好的工作查找功能,但它搜索所有列。现在我尝试对范围定义进行各种更改,并为 A 列设置了选择限制。
我遇到的问题是它无视任何限制并以自己的方式进行。代码如下,它使用了两个函数,第一个是 Find,第二个是 Find Next。
谁能帮我一把,告诉我如何将搜索限制在电子表格的 A 列。
Private Sub Find_Click()
Worksheets("Master").Activate
Dim strFind As String
Dim FirstAddress As String
Dim rSearch As Range
Set rSearch = Range("a1", Range(A:A).End(xlUp))
Dim f As Integer
strFind = Me.TextBox1.Value
With rSearch
Set c = .Find(strFind, LookIn:=xlValues)
If Not c Is Nothing Then
updateFields anchorCell:=c
FirstAddress = c.Address
Do
f = f + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> FirstAddress
If f > 1 Then
Select Case MsgBox("There are " & f & " instances of " & strFind, vbOKCancel Or vbExclamation Or vbDefaultButton1, "Multiple entries")
Case vbOK
Case vbCancel
End Select
End If
Else: MsgBox strFind & " not listed"
End If
End With
谢谢
【问题讨论】:
-
您能否通过在 Excel 中执行 Ctrl + F 来检查是否设置了在整个工作簿(而不是当前工作表)中搜索的选项?这可能会导致这种情况。