Vba 找到一个字符串,将其下的数据输入另一个工作表

Vba 找到一个字符串,将其下的数据输入另一个工作表,vba,excel,Vba,Excel,我想做一些代码来搜索所有工作表中的字符串“Question”,然后在它下面取“5”行。然后将这5行从“B2”行中取出,放入工作表“模板”中 这是我目前的代码: Dim SearchString As String Dim SearchRange As Range, cl As Range Dim FirstFound As String Dim sh As Worksheet ' Set Search value SearchString = "Q

我想做一些代码来搜索所有工作表中的字符串“Question”,然后在它下面取“5”行。然后将这5行从“B2”行中取出,放入工作表“模板”中

这是我目前的代码:

    Dim SearchString As String
    Dim SearchRange As Range, cl As Range
    Dim FirstFound As String
    Dim sh As Worksheet
    ' Set Search value
    SearchString = "Question"
    Application.FindFormat.Clear
    ' loop through all sheets
    For Each sh In ActiveWorkbook.Worksheets
        ' Find first instance on sheet
        Set cl = sh.Cells.Find(What:=SearchString, _
            After:=sh.Cells(1, 1), _
            LookIn:=xlValues, _
            LookAt:=xlPart, _
            SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, _
            MatchCase:=False, _
            SearchFormat:=False)
        If Not cl Is Nothing Then
            ' if found, remember location
            FirstFound = cl.Address
            ' format found cell
            Do
                cl.Font.Bold = True
                cl.Interior.ColorIndex = 3
                ' find next instance
                Set cl = sh.Cells.FindNext(After:=cl)
            Loop Until FirstFound = cl.Address
        End If
    Next

这段代码所做的就是查找字符串。如何获取字符串下面的数据并将其复制到“模板”工作表中?

您将希望投资于:


我想知道如何获取字符串下面的数据,这段代码所做的就是找到它。
Dim RangeToCopy As Range, DestRow As Long
Set RangeToCopy = sh.Range(cl.Offset(1, 0), cl.Offset(5, 0))
RangeToCopy.Copy
DestRow = Sheets("Template").Range("B" & Rows.Count).End(xlUp).Row + 1
Sheets("Template").Range("B" & DestRow).PasteSpecial xlPasteValues