Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 将上次使用的4行复制并粘贴到下一个可用的4行中_Excel_Vba - Fatal编程技术网

Excel 将上次使用的4行复制并粘贴到下一个可用的4行中

Excel 将上次使用的4行复制并粘贴到下一个可用的4行中,excel,vba,Excel,Vba,正如标题所描述的,我需要将数据和格式从同一工作表中的最后4行复制到下一个可用的4行 这可能是一个相当简单的代码,但我刚刚开始使用VBA,希望有人能帮助我;我希望一旦我开始做一些零碎的工作,我就能积累我的知识 提前谢谢。这里有一个简单的方法,可以让你知道这会是什么样子 Option Explicit Public Sub CopyRows() Dim Ws As Worksheet Dim LastRow As Long ' Replace Sheet1 with yo

正如标题所描述的,我需要将数据和格式从同一工作表中的最后4行复制到下一个可用的4行

这可能是一个相当简单的代码,但我刚刚开始使用VBA,希望有人能帮助我;我希望一旦我开始做一些零碎的工作,我就能积累我的知识


提前谢谢。

这里有一个简单的方法,可以让你知道这会是什么样子

Option Explicit

Public Sub CopyRows()
    Dim Ws As Worksheet
    Dim LastRow As Long

    ' Replace Sheet1 with your sheet name
    Set Ws = ThisWorkbook.Worksheets("Sheet1")

    With Ws
        ' Get last row number (A = column letter, use something that has data on it, if A is empty for you)
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

        .Range("A" & LastRow - 3, "A" & LastRow).EntireRow.Copy ' Source
        .Range("A" & LastRow + 1).PasteSpecial xlPasteAll       ' Destination (xlPasteAll = values & formatting)
    End With

    ' Remove the copy selection
    Application.CutCopyMode = False
End Sub
我建议查看文档以了解有关VBA对象的方法和属性的更多信息:

最快的入门方法可能是录制宏:宏录制的所有操作都将在编辑器中可见,因此您可以查看如何使用VBA执行这些操作。因为所有的东西都被记录下来了,所以代码通常非常庞大,当然也不理想。但是,如果你一次只做一些小动作,这可能是一个快速发现可能性的方法

  • 开始宏录制
  • 做一件事
  • 看看代码,试着理解它

  • 为了更好地理解宏,您应该仔细阅读Microsoft:或类似软件提供的文档。

    此处介绍了录制宏的所有步骤:尝试一下!谢谢你,Jugger,这是我需要的。非常感谢。