Vba 宏,用于在excel文件中搜索包含少量选项卡的文本,并使用搜索匹配项创建新文件

Vba 宏,用于在excel文件中搜索包含少量选项卡的文本,并使用搜索匹配项创建新文件,vba,excel,search,Vba,Excel,Search,我有一个包含多个选项卡的excel文件 我需要创建一个宏,该宏将在“所有”选项卡中进行搜索,并创建一个包含所有搜索匹配项的新文件 知道怎么做吗?如果可以帮助启动,请参阅下面的代码。我不知道您希望如何处理找到的值 Option Explicit Sub find() Dim WS_Count As Integer Dim i As Integer Dim myValue As Variant Dim Rng As Range Dim wkb As Workbook Dim lastrow As

我有一个包含多个选项卡的excel文件

我需要创建一个宏,该宏将在“所有”选项卡中进行搜索,并创建一个包含所有搜索匹配项的新文件


知道怎么做吗?

如果可以帮助启动,请参阅下面的代码。我不知道您希望如何处理找到的值

Option Explicit

Sub find()

Dim WS_Count As Integer
Dim i As Integer
Dim myValue As Variant
Dim Rng As Range
Dim wkb As Workbook
Dim lastrow As Long


WS_Count = Worksheets.Count


myValue = InputBox("Please enter the value that you want to look for:")


For i = 1 To WS_Count

        With Worksheets(i).UsedRange

            Set Rng = .find(What:=myValue)



                If Not Rng Is Nothing Then

                    MsgBox ("The value" & " " & myValue & " " & "found in" & " " & ActiveWorkbook.Worksheets(i).Name & " " & Rng.Address)
                    'do whatever you want with the string found...



                Else

                    MsgBox ("Nothing found in" & " " & ActiveWorkbook.Worksheets(i).Name)

           End If

        End With

    Next i


End Sub

你能解释一下你到目前为止尝试了什么,或者你的问题到底是什么吗?我只想创建一个excel宏来搜索一个“单词”,如果搜索找到它,宏将创建一个新文件,其中包含从搜索中找到的所有积极结果。你知道怎么做吗?