find一个string,把它下面的数据,并将其input到另一个工作表

我想要一个代码来searchstring“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 

所有这些代码是findstring。 如何获取string下的数据并将其复制到“模板”工作表?

您将需要投资.Offset方法 :

 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