如何在Excel中将数据复制到空白行然后删除原始文件

时间:2018-07-11 20:15:55

标签: excel-vba find paste

我在excel中编码时遇到困难,无法弄清楚该怎么做。我正在尝试从一行中获取数据,在同一工作簿的同一张工作表的不同区域中搜索空白行,使用仅值设置复制数据,然后删除原始数据。

到目前为止,这就是我所拥有的,唯一的问题是我不确定如何告诉它粘贴数据。问号指示我被卡在哪里。我什至需要其他东西还是可以直接进入代码的“ selection.pastespecial”部分?

任何帮助或指导将不胜感激,谢谢!

   Sub Find_Blank_And_Fill()
    Dim cnter As Integer

    lastRow = Cells(Rows.Count, 1).End(xlUp).Row
    cnter = 0

    For i = 1 To lastRow
        If IsEmpty(Cells(i, 1)) Then
            Range("B29:F29").Select
            Selection.copy
            ????
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            End Select
            cnter = cnter + 1
        End If
    Next i
End Sub

有一张照片可以帮助我更好地理解它。

Visual Description

此致

ProWHP

1 个答案:

答案 0 :(得分:0)

您已经拥有的东西将起作用。但是,我将进行以下编辑:

Sub Find_Blank_And_Fill()
Dim cnter As Integer

lastRow = Cells(Rows.Count, 1).End(xlUp).Row
cnter = 0
Range("B29:F29").copy 'Avoid using "Select"! Also, this way you only copy once.

For i = 3 To lastRow 'Start your fill operation after your known rows
    If IsEmpty(Cells(i, 1)) Then
        Cells(i,2).PasteSpecial Paste:=xlPasteValues 'Simplified
        cnter = cnter + 1 'Why is this here?  It's counting empty rows right now
    End If
Next i
application.cutcopymode = false 'Turns off the box around the area you copied
End Sub
相关问题