简体   繁体   English

在找到 function 后创建循环以复制/粘贴 vba 循环

[英]Creating loop to copy/paste vba loop after find function

Im trying to create a loop in excel that will find a word and then copy and paste all cells underneath the word into another workbook until a blank cell.我试图在 excel 中创建一个循环,它将找到一个单词,然后将单词下面的所有单元格复制并粘贴到另一个工作簿中,直到出现空白单元格。 Im really new to VBA so please bare with我对 VBA 真的很陌生,所以请裸露

Sub CopyRows()

Dim Found As Range
Dim NextFreeCell As Range
Dim wkDest As Worksheet

Set wsDest = Workbooks("sample_bills (version 1).xlsx").Worksheets("sample_bills")
Set NextFreeCell = wsDest.Cells(Rows.Count, "C").End(xlUp).Offset(RowOffset:=1)
Set Found = Cells.Find(What:="Paid", LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False)
    If Found Is Nothing Then
    MsgBox "ERROR"
    Else
    i = Found.Row
    j = Found.Column

    End If

    Do
    NextFreeCell = Cells(i, j)
    i = i + 1
    Loop Until IsEmpty(Cells(i, j))

End Sub

This is what ive got so far but will only copy and paste the word paid into the other workbook, and won't continue to do the rest underneath.这是我到目前为止所得到的,但只会将“支付”这个词复制并粘贴到另一个工作簿中,并且不会继续在下面做 rest。 Any help would be appreciated:)任何帮助,将不胜感激:)

Update: Managed to solve this by moving the line更新:设法通过移动线路来解决这个问题

Set NextFreeCell = wsDest.Cells(Rows.Count, "C").End(xlUp).Offset(RowOffset:=1)

into the loop进入循环

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM