MAcro will not Copy and Paste Row to New WS - Not the Same Size?

SAMCRO2014

Board Regular
Joined
Sep 3, 2015
Messages
158
Hi there. I am trying to prepare a macro with two For...if functions and it keeps telling me that the copy and paste area are not the same size when they are. IS there coding to get around this:

Sub ISS_vs_SPS()


'Set variables
Dim ISS As Worksheet
Set ISS = ThisWorkbook.Sheets("ISS")

Dim SPS As Worksheet
Set SPS = ThisWorkbook.Sheets("SPS")

Dim LastRowISS As Long
LastRowISS = ISS.Cells(Rows.Count, 1).End(xlUp).Row

Dim LastRowSPS As Long
LastRowSPS = SPS.Cells(Rows.Count, 1).End(xlUp).Row

Dim x As Long

'Turn off Printing and screen updating to speed up macro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.PrintCommunication = False

'If CC ("A2") and PRI("D2") on the ISS and match the CC ("A2) and PRI ("C2") on the SPS worksheets then copy and past the entire row from SPS worksheet to ISS worksheet starting at Cell N2.....loop

For x = 2 To LastRowISS
If ISS.Cells(x, 1).Value = SPS.Cells(x, 1).Value Then
If ISS.Cells(x, 4).Value = SPS.Cells(x, 3).Value Then
SPS.Cells(x, 1).EntireRow.Copy Destination:=ISS.Cells(x, 14)
End If
End If
Next x

'Turn off Printing and screen updating to speed up macro
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.PrintCommunication = True

MsgBox "All Done!!!"

End Sub


Thanks!
 
Last edited:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
In your code,

SPS.Cells(x, 1).EntireRow.Copy Destination:=ISS.Cells(x, 14)

won't work. As the row sizes indeed are different! That is, the no of columns copies are more than the number of columns selected to be pasted.

Perhaps, you would need to count the number of columns copied and then set the paste area accordingly.
 
Upvote 0
Ok. I see what you are saying. I need to paste 15 columns so how would I write the coding for this. Sorry, I am really new to macros.

Would it be:
SPS.Cells(x,1:x,15) Destination:=ISS.Cells(x,14:x,28)
 
Upvote 0
How about
Code:
SPS.Cells(x, 1).Resize(, 15).Copy ISS.Cells(x, 14)
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,478
Messages
6,125,040
Members
449,205
Latest member
Eggy66

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