Excel VBA在工作表中查找文本,复制范围,粘贴到其他工作表

我比较新的Excelmacros,并不知道如何解决我所需要的。 基本上,我正在写一个代码,在当前位于B63(“今天”)的工作表中查找文本,从所find的值中select行,直到它应该停在的下一个值B83(“明天”)这个案例。 问题是每次下载新数据时,“今天”和“明天”都会上下移动。

我已经试过为此编写代码,但没有取得任何成功,在这一点上,我甚至不确定我采取了正确的方法。 这是我有什么帮助,将不胜感激:

昏暗的细胞作为范围

For i = 1 To 100 For f = 30 To 100 Sheets("Download").Select If Cells(i, "B").Value = "Today" Then If Cells(f, "B").Value = "Tomorrow" Then 'Insert code to select rows from "i" to "f"-1 (one above f) Selection.Copy Sheets("Statements").Select Range("A3").Select ActiveSheet.Paste End If Next i 

尝试这个

 Sub test() Dim td As Range, tm As Range With Sheets("Download") Set td = .[B:B].Find("today") Set tm = .[B:B].Find("tomorrow") If (Not td Is Nothing) And (Not tm Is Nothing) Then .Rows(td.Row & ":" & tm.Offset(-1, 0).Row).Copy Sheets("Statements").[A1] End If End With End Sub 

UPDATE

尝试这个

 Sub test() Dim td&, tm&, n&, cl As Range, Dwnld As Worksheet, Stmnt As Worksheet td = 0: tm = 0 Set Dwnld = Sheets("Download"): Set Stmnt = Sheets("Statements") With Dwnld n = .Cells.Find("*", , , , xlByRows, xlPrevious).Row For Each cl In .Range("B1:B" & n) If LCase(cl.Value) = "today" Then td = cl.Row If LCase(cl.Value) = "tomorrow" Then tm = cl.Offset(-1, 0).Row If td > 0 And tm > 0 Then .Rows(td & ":" & tm).Copy Stmnt.Range("A" & Stmnt.Cells(Rows.Count, "A").End(xlUp).Row + 1) td = 0: tm = 0 End If Next cl End With End Sub 

资源

在这里输入图像说明

目的地

在这里输入图像说明