[英]Excel vba find text in sheet, copy range, paste to other sheet
我对excel宏非常陌生,无法弄清楚如何修复所需的内容。 基本上,我正在编写一个代码,以在工作表中查找文本,当前工作表位于B63(“今天”),从找到的值中选择该行,直到它应在B83(“ Tomorrow”)处停止的下一个值为止这个案例。 问题在于,每次下载新数据时,“今天”和“明天”都会上下移动。
我已经尝试为此编写代码,但没有取得任何成功,在这一点上,我什至不确定我是否采用了正确的方法。 这是我所拥有的,任何帮助将不胜感激:
暗单元格范围
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
资源
目的地
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.