简体   繁体   中英

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.

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.

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. Best of luck!

please see below (ps. I have not tested it)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM