VBA Excel 中的代码

VBA Excel 中的代码

我需要宏方面的帮助。目标是在每个工作表中查找特定文本。如果找到此文本,宏将继续执行下一个代码。如果未找到文本,宏将跳至下一个工作表并执行相同操作。我有以下代码。你能帮帮我吗?

  For Each wrkb In Workbooks
    If Not (wrkb Is ThisWorkbook) Then
    wrkb.Activate


        For Each wrksheet In wrkb.Worksheets

                Dim rng As Range
                 Range("A1:K1000").Select
                Set rng = Selection.Find(What:="AAABBB")
                If Not rng Is Nothing Then
                 wrksheet.Activate
                ElseIf rng Is Nothing Then
                Next wrksheet
                End If

如果没有“for”,“Next wrksheet”就不起作用。

...当条件“if”满足时,将处理下一个代码(这里未指定)...

答案1

草稿代码:

For Each wbk In Workbooks
    For Each sht In wbk.Sheets
        If wbk Is ThisWorkbook Then Exit For
        With sht.UsedRange
            Set OneCell = .Find(What:="AAABBB")
            Do
                If OneCell Is Nothing Then Exit Do
                Call PerformNeededAction(OneCell)
                OneCell = .FindNext(OneCell)
            Loop
        End With
    Next sht
Next wbk

相关内容