简体   繁体   中英

How to paste range of cells in the next empty table row?

I would like to copy a range of cells from one table to another on a different sheet, but when it pastes to the new table it overrides existing information.

Here is the code I am currently using:

Dim wsCopy As Worksheet
Dim wsDest As Worksheet
Dim db As Worksheet

Dim lCopy As Long
Dim lDest As Long

Dim lCopy2 As Long
Dim lDest2 As Long

Set db = Sheet1

db.range("B6:F1000").ClearContents

  Sheets("Create_kit").range("B4").Value = Sheets("Update_kit").range("B3").Value
  Sheets("Create_kit").range("C4").Value = Sheets("Update_kit").range("C3").Value

  Set wsCopy = Worksheets("Update_kit") 'Copies table
  Set wsDest = Worksheets("Create_kit") 'Pastes table

  lCopy = wsCopy.Cells(wsCopy.Rows.count, "B").End(xlUp).Row
  lDest = wsDest.Cells(wsDest.Rows.count, "B").End(xlUp).Offset(1).Row

  'Copies any cell within the table
  wsCopy.range("B5:F" & lCopy).Copy
  wsDest.range("B" & lDest).PasteSpecial xlPasteValues

I tried changing Offset(1) to Offset(0) but I did not notice any changes after running the code.

I would like to have the new data pasted in the next empty row in column B in the new table. I have tried to look at other asked questions but I have been unsuccessful in finding a solution.

Any help is appreciated!

您能否确认要复制/粘贴的B列中没有空单元格,因为您使用的函数“ wsCopy.Cells(wsCopy.Rows.count,“ B”)。End(xlUp).Row“可以找到最后一行,中间没有空单元格。

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