Copy & Paste special

cgriff

Board Regular
Joined
Aug 26, 2002
Messages
201
I have code below and I am trying to paste special values and formatting with no luck, any help would be greatly appreciated

Chris


Sub Copy_Paste_Below_Last_Cell_new()




'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 = ThisWorkbook.Worksheets(8)
Set wsDest = ThisWorkbook.Worksheets("Data collect")

'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:G" & lCopyLastRow).Copy _
wsDest.Range("A" & lDestLastRow)


End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Try changing

Code:
wsCopy.Range("A2:G" & lCopyLastRow).Copy _
wsDest.Range("A" & lDestLastRow)

to

Code:
    wsCopy.Range("A2:G" & lCopyLastRow).Copy
    
    With wsDest.Range("A" & lDestLastRow)
        .PasteSpecial xlValues
        .PasteSpecial xlFormats
    End With
 
Last edited:
Upvote 0
You should also add

Code:
Application.CutCopyMode = False

after the code I posted :oops:
 
Upvote 0
I cant get this to work for the life of me. Ive been staring at this and cant figure out where its wrong. I just want to paste values. i added paste special and get error

Sub Paste_Matrix()
'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("test.xlsm").Worksheets("Matrix")
Set wsDest = Workbooks("Test2.xlsx").Worksheets("Matrix")

'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("A1:J" & lCopyLastRow).Copy_
wsDest.Range ("A" & lDestLastRow)
.PasteSpecial xlValues
.PasteSpecial xlFormats


Application.CutCopyMode = False

End Sub
 
Upvote 0
See post#2 ;)
When I run the original VBA image#1 it work but paste formulas, but when I add the special i get image#2 it give compile error
Image#1
1600196461928.png

Image#2
1600196599350.png
 
Upvote 0
You still haven't looked at post number 2 properly
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,737
Members
449,050
Latest member
excelknuckles

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