VBA Excel"什么"不再看.find方法

时间:2015-05-18 10:52:10

标签: excel-vba vba excel

当我运行我编写的一个宏时,我发现了一个问题。我无法找到根。

我正在寻找包含单词RCS和我的子" FindMultipleOccurrences"的列中的所有值。如果我不打电话给另一个名为" RCS"" FindMultipleOccurrences"我也在寻找一些空值。

但是如果RCS sub调用sub" Sub FindMultipleOccurrences() Dim rngSearch As Range, rngLast As Range, rngFound As Range Dim strFirstAddress As String Worksheets("RCS").Range("B5:J1000").Delete Set rngSearch = Worksheets("Ongoing").Range("B:B") Set rngLast = rngSearch.Cells(rngSearch.Cells.Count) Set rngFound = rngSearch.Find(What:="RCS", After:=rngLast, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False) 'buscando RCS If Not rngFound Is Nothing Then strFirstAddress = rngFound.Address Do Set rngFound = rngSearch.FindNext(rngFound) MsgBox rngFound.Address ' Call RCS(rngFound) Loop Until rngFound.Address = strFirstAddress End If MsgBox "done" End Sub "不再查看RCS条目,而是查找空值。

我该如何避免这个问题?

我的宏(请注意两个宏尚未完成):

Sub RCS(rngo As Range)

    Set Row1 = Range(rngo.Address).Offset(7, -1).Resize(, 13).Find("", LookIn:=xlValues, LookAt:=xlWhole)

    If Row1 Is Nothing Then
            Set row2 = Range(rngo.Address).Offset(8, -1).Resize(, 13).Find("", LookIn:=xlValues, LookAt:=xlWhole)
            If row2 Is Nothing Then
                Set rower = Range(rngo.Address).Offset(9, -1).Resize(, 13).Find("", LookIn:=xlValues, LookAt:=xlWhole)
            Else
                Set rower = row2
            End If
    Else
        Set rower = Row1
    End If
End Sub

Makro 2:

ThreadPool mockInstance = mock(ThreadPool .class);
Whitebox.setInternalState(ThreadPool.class, "INSTANCE", mockInstance);

1 个答案:

答案 0 :(得分:0)

当你拨打第二个.Find命令时,你基本上取消了第一个和后续.FindNext命令将不会从原始.Find继续执行。

使用其他方法来实现偏移空白单元格位置。

If CBool(Application.CountBlank(Range(rngo.Address).Offset(7, -1).Resize(, 13))) Then
    Set Rower = Range(rngo.Address).Offset(7, -1).Resize(, 13).SpecialCells(xlCellTypeBlanks).Cells(1, 1)

我不清楚连续操作的目的是什么。如果您正在查找空白列并且无法找到任何内容,则将范围向下移动一个单元格并再次搜索不应找到任何内容。