vba 如何在excel中粘贴B列的最后一行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13635089/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to paste in last row of Column B in excel?
提问by Mowgli
I need to cut cells from H2:L2 to all the way down and paste it in last row of column B.
我需要将单元格从 H2:L2 一直向下剪切并将其粘贴到 B 列的最后一行。
Data will be different everytime so I cannot hard code any range.
数据每次都会不同,所以我不能硬编码任何范围。
VBA code would be nice, to cut from H2:L2 down and paste/insert in the last row of Column B.
VBA 代码会很好,从 H2:L2 向下剪切并粘贴/插入 B 列的最后一行。
So far I got.
到目前为止我得到了。
Range("H2:L2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Cut
回答by Desert Spider
Here is a segment of code that should accomplish what you are looking for.
这是一段代码,应该可以完成您正在寻找的内容。
Start code including your cut segment...
Dim lastRow As String
lastRow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row + 1
Range("B" & lastRow).Select
Selection.PasteSpecial
Rest of code...
There are a number of books that will help with this type of coding and have step by step trainig. I am partial to the series published by Microsoft "Step by Step" series. Best of luck!
有许多书籍可以帮助进行这种类型的编码,并提供逐步培训。我偏爱微软“Step by Step”系列发布的系列。祝你好运!
回答by Wheeliam
please see below (ps. I have not tested it)
请看下面(ps。我没有测试过)
Sub copypaste()
Dim wb As Workbook, ws As Worksheet, rng As Range, lr As Long
Set wb = Workbooks("Name_of_your_workbook.xlsm")
Set ws = wb.Sheets("Your_Sheet_Name")
Set rng = ws.Range("H2:L2")
lr = Sheet("Your_Sheet_Name").Cells(Rows.Count, "B").End(xlUp).Row
rng.Copy Destination:=ws.Range("B" & lr)
Cells(1, 1).Select
End Sub