stirlingmw
Board Regular
- Joined
- Feb 18, 2013
- Messages
- 75
Good morning I have the following code which clears the contents of one Worksheet "Project Summary" then copies and pastes certain columns of data from another worksheet "Project Master" and pastes them into "Project Summary". the problem I have is that when I run the code it causes the the program to stall producing "Not Responding" error. This error does clear after approximately 20 seconds when the code has finished running. Is there anything I can do to the code to prevent this happening and speed up the process?
Thanks
Steve
Code:
Private Sub CommandButton2_Click()
Dim lastrow As Long, erow As Long
ActiveSheet.Unprotect "-------"
Application.ScreenUpdating = False
Worksheets("Project Summary").Cells(Rows.count, 1).End(xlUp).Select
Selection.ClearContents
Worksheets("Project Summary").Range("A1").Select
lastrow = Worksheets("Project Master").Cells(Rows.count, 1).End(xlUp).Row
For i = 2 To lastrow
Worksheets("Project Master").Cells(i, 1).Copy
erow = Worksheets("Project Summary").Cells(Rows.count, 1).End(xlUp).Offset(1, 0).Row
Worksheets("Project Master").Paste Destination:=Worksheets("Project Summary").Cells(erow, 1)
Worksheets("Project Master").Cells(i, 5).Copy
Worksheets("Project Master").Paste Destination:=Worksheets("Project Summary").Cells(erow, 2)
Worksheets("Project Master").Cells(i, 14).Copy
Worksheets("Project Master").Paste Destination:=Worksheets("Project Summary").Cells(erow, 3)
Worksheets("Project Master").Cells(i, 7).Copy
Worksheets("Project Master").Paste Destination:=Worksheets("Project Summary").Cells(erow, 4)
Worksheets("Project Master").Cells(i, 10).Copy
Worksheets("Project Master").Paste Destination:=Worksheets("Project Summary").Cells(erow, 5)
Worksheets("Project Master").Cells(i, 71).Copy
Worksheets("Project Master").Paste Destination:=Worksheets("Project Summary").Cells(erow, 6)
Worksheets("Project Master").Cells(i, 63).Copy
Worksheets("Project Master").Paste Destination:=Worksheets("Project Summary").Cells(erow, 7)
Worksheets("Project Master").Cells(i, 64).Copy
Worksheets("Project Master").Paste Destination:=Worksheets("Project Summary").Cells(erow, 8)
Worksheets("Project Master").Cells(i, 46).Copy
Worksheets("Project Master").Paste Destination:=Worksheets("Project Summary").Cells(erow, 9)
Worksheets("Project Master").Cells(i, 47).Copy
Worksheets("Project Master").Paste Destination:=Worksheets("Project Summary").Cells(erow, 10)
Worksheets("Project Master").Cells(i, 48).Copy
Worksheets("Project Master").Paste Destination:=Worksheets("Project Summary").Cells(erow, 11)
Next i
Application.CutCopyMode = False
Range("A1").Select
ActiveSheet.Protect "-------"
Application.ScreenUpdating = True
End Sub
Thanks
Steve