SAMCRO2014
Board Regular
- Joined
- Sep 3, 2015
- Messages
- 160
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!
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: