简体   繁体   中英

VBA Excel Copy and paste values to new work with set range after last row

copying and pasting range of cells but only values to new workbook after last line. My copy worksheet data range starts at o3 and goes to r100. data will change. the new work book where i want to start pasting just the values starts at cell m13. by clicking button i want pull new data under a blank line.

I have researched code that either does copy and paste to different workbooks or copying to last row. but not both.

Sub xtrnsf_to_other_wrkbook()

'Find the last used row in both sheets and copy and paste data below existing data.

Dim wsCopy As Worksheet
Dim wsDest As Worksheet
Dim lCopyLastRow As Long
Dim lDestLastRow As Long

  'Set variables for copy and destination sheets

  Set wsCopy = Workbooks("LP sort2.xlsm").Worksheets("Chalks")
  Set wsDest = Workbooks("PC.xlsm").Worksheets("Planner's Checklist")

  '1. Find last used row in the copy range based on data in column A

  lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "O").End(xlUp).Row

  '2. Find first blank row in the destination range based on data in column A

  'Offset property moves down 1 row
  lDestLastRow = wsDest.Cells(wsDest.Rows.Count, "M").End(xlUp).Offset(2).Row

  '3. Copy & Paste Data  
     wsCopy.Range("O3:R).Copy _
       wsDest.Range("M" & lDestLastRow)


End Sub

My copy worksheet data range starts at O3 and goes to r100. data will change. the new work book where i want to start pasting just the values starts at cell M13. by clicking button i want pull new data under a blank line.

You just need to change the copy line as you left out the end of the source range.

Paste special will copy the values not the formulae.

 wsCopy.Range("O3:R" & lCopyLastRow).Copy 
 wsDest.Range("M" & lDestLastRow).pastespecial xlvalues

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