[英]How to paste in last row of Column B in excel?
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
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.
我参与了由Microsoft发布的“ Step by Step”系列文章。 Best of luck!
祝你好运!
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.