vba copy and paste from one worksheet to another using different paste special method

mychi11

Board Regular
Joined
May 11, 2020
Messages
95
Office Version
  1. 2016
Platform
  1. Windows
here is my code . I was wondering if i can PasteSpecial xlPasteValues, xlPasteSpecialOperationAdd for column C and H only ? , while others just PasteSpecial xlPasteValues

Sub Copy_Paste_Below_Last_Cell()
'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("inv.xlsx").Worksheets(1)
Set wsDest = Workbooks("labinventory.xlsm").Worksheets("Master")

'1. Find last used row in the copy range based on data in column A
lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "A").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, "A").End(xlUp).Offset(1).Row

'3. Copy & Paste Data
wsCopy.Range("A2:L" & lCopyLastRow).Copy
wsDest.Range("A" & lDestLastRow).PasteSpecial xlPasteValues

End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Maybe in parts:

VBA Code:
  '3. Copy & Paste Data
  'wsCopy.Range("A2:L" & lCopyLastRow).Copy
  wsCopy.Range("A2:B" & lCopyLastRow).Copy
  wsDest.Range("A" & lDestLastRow).PasteSpecial xlPasteValues
  
  wsCopy.Range("C2:C" & lCopyLastRow).Copy
  wsDest.Range("C" & lDestLastRow).PasteSpecial xlPasteValues, xlPasteSpecialOperationAdd
  
  wsCopy.Range("D2:G" & lCopyLastRow).Copy
  wsDest.Range("D" & lDestLastRow).PasteSpecial xlPasteValues
  
  wsCopy.Range("H2:H" & lCopyLastRow).Copy
  wsDest.Range("H" & lDestLastRow).PasteSpecial xlPasteValues, xlPasteSpecialOperationAdd
  
  wsCopy.Range("I2:L" & lCopyLastRow).Copy
  wsDest.Range("I" & lDestLastRow).PasteSpecial xlPasteValues
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,370
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top