[英]What is wrong with this code? .Find , VBA
我有两个子项,第一个子项“ Find”在G列中找到所有值,范围(G1:G10),我有三个值,所以它循环3次并给我值。
现在,我正在调用第二个子“ Find2”以在A列范围(A1:A10)中找到该值。 问题是它只运行一次..它不循环三次以获取3个值。 任何想法 ?。 为什么它不起作用。
Sub Find()
Set shtSheet1 = Sheets("Sheet1")
With shtSheet1.Range("G1:G10")
Set V = .find("*", LookIn:=xlValues)
If Not V Is Nothing Then
FirstAddress = V.Address
Do
X = V
Call Find2
Set V = .FindNext(V)
Loop While Not V Is Nothing And V.Address <> FirstAddress
End If
End With
End Sub
第二子
Public Sub Find2()
Set shtSheet1 = Sheets("Sheet1")
Set shtSheet2 = Sheets("Sheet2")
With shtSheet1.Range("A1:A10")
Set C = .find(X, LookIn:=xlValues)
If Not C Is Nothing Then
MsgBox X
End If
End With
End Sub
我认为在子例程中使用.Find()会干扰主例程中的.FindNext()。
我同意加里(Gary)的说法,这有一些干扰。 而不是在您的子例程中使用Find(),请看这是否对您有用。
Public Sub Find2()
Dim shtSheet1 As Worksheet
Dim C As Range
Set shtSheet1 = Sheets("Sheet1")
Set C = shtSheet1.Range("A1:A10")
If Not IsError(Application.Match(X, C, 0)) Then
MsgBox X
End If
End Sub
采用
private Function Find2()
end function
子安装
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.