Copy & Paste if condition is met

cgriff

Board Regular
Joined
Aug 26, 2002
Messages
201
Hi all I have this code And I need to add a condition if cells are >0 then paste any help is much 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

With wsDest.Range("A" & lDestLastRow)
.PasteSpecial xlValues
.PasteSpecial xlFormats
End With

Application.CutCopyMode = False


End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi all I have this code And I need to add a condition if cells are >0 then paste any help is much 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

With wsDest.Range("A" & lDestLastRow)
.PasteSpecial xlValues
.PasteSpecial xlFormats
End With

Application.CutCopyMode = False


End Sub

Just to clarify I need cells in sheet 1 column A > 0 to be pasted to Sheet 2 Thank you
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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