简体   繁体   English

如何在Excel中粘贴B列的最后一行?

[英]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.

相关问题 如何将列B的所有行粘贴到Excel VBA中的列A的第n行 - How to paste from column B all rows to column A's nth row in Excel VBA Excel宏:如果列B具有“ X”,则复制整行并粘贴到名为“列B”的工作表中 - Macro for Excel: If Column B has “X”, then copy entire row and paste in Worksheet named “Column B” 如何找到最后一行并将公式粘贴到列的最后一个单元格 - How to find last row and paste the formula to the last cell of column 不确定如何将公式动态粘贴到最后一列和最后一行 - Unsure How to Dynamically Paste a Formula To Last Column and Last Row Excel VBA:如何将值粘贴到表的最后一行的第一个单元格中? - Excel VBA: How to paste a value in the first Cell of the last row of a table? 如何在VBA Excel中使用最后一行概念粘贴数据 - how to paste data using last row concept in VBA excel 如果 A 列(或 B;C 等)为空,则在工作表之间复制并粘贴最后一行将覆盖值 - Copy between sheets and paste last row will overwrite values if column A (or B; C etc.) is empty VBA 从列(B 到 G)复制和粘贴循环到 A 列的最后一行 - VBA copy & Paste loop from columns (B to G) to the last row of column A 如何引用特定行中最后使用的列并在其中粘贴特定值 - How to reference last used column in a certain row and paste certain value in there Excel宏查找列B中的最后一行,选择另一个单元格A1,将公式从A1拖动到B中的最后一行 - Excel Macro Find Last Row In Column B, Select another cell A1, drag formula from A1 to last row in B
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM