Where am I going wrong with this code? -

Si1209

Board Regular
Joined
Jan 27, 2016
Messages
50
At random times throughout running this macro it keeps coming back with the dreaded "1004 PasteSpecial method of Range class failed" I'm not sure why this is and I cant see anything throughout the code that sticks out as to what could be wrong. Its not like it stops at a certain place either it will be at random points in the macro.

Thanks

Code:
Sub CMSImport()


Application.ScreenUpdating = False
On Error GoTo e:
Application.ScreenUpdating = 1
sk = Range("B2") ''''''' change skill number as required"
ImpDate1 = Range("B1")
Range("A11:W41").Select
Selection.ClearContents

Set cvsSrv = cvsApp.Servers(1) '(cvsApp.Servers.Count) '''''' we set a reference to the server here
Call doRep5("Historical\Designer\GI Skill Perf (I) ASA", sk, ImpDate1)
ThisWorkbook.ActiveSheet.Cells(11, 1).PasteSpecial
logout
Application.ScreenUpdating = 0

On Error GoTo e:
Application.ScreenUpdating = 1
sk = Range("B44") ''''''' change skill number as required"
ImpDate1 = Range("B1")
Range("A45:W74").Select
Selection.ClearContents

Set cvsSrv = cvsApp.Servers(1) '(cvsApp.Servers.Count) '''''' we set a reference to the server here
Call doRep5("Historical\Designer\GI Skill Perf (I) ASA", sk, ImpDate1)
ThisWorkbook.ActiveSheet.Cells(45, 1).PasteSpecial
logout
Application.ScreenUpdating = 0

On Error GoTo e:
Application.ScreenUpdating = 1
sk = Range("B77") ''''''' change skill number as required"
ImpDate1 = Range("B1")
Range("A78:W109").Select
Selection.ClearContents

Set cvsSrv = cvsApp.Servers(1) '(cvsApp.Servers.Count) '''''' we set a reference to the server here
Call doRep5("Historical\Designer\GI Skill Perf (I) ASA", sk, ImpDate1)
ThisWorkbook.ActiveSheet.Cells(78, 1).PasteSpecial
logout
Application.ScreenUpdating = 0

On Error GoTo e:
Application.ScreenUpdating = 1
sk = Range("B110") ''''''' change skill number as required"
ImpDate1 = Range("B1")
Range("A111:W141").Select
Selection.ClearContents

Set cvsSrv = cvsApp.Servers(1) '(cvsApp.Servers.Count) '''''' we set a reference to the server here
Call doRep5("Historical\Designer\GI Skill Perf (I) ASA", sk, ImpDate1)
ThisWorkbook.ActiveSheet.Cells(111, 1).PasteSpecial
logout
Application.ScreenUpdating = 0

On Error GoTo e:
Application.ScreenUpdating = 1
sk = Range("B176") ''''''' change skill number as required"
ImpDate1 = Range("B1")
Range("A177:W208").Select
Selection.ClearContents

Set cvsSrv = cvsApp.Servers(1) '(cvsApp.Servers.Count) '''''' we set a reference to the server here
Call doRep5("Historical\Designer\GI Skill Perf (I) ASA", sk, ImpDate1)
ThisWorkbook.ActiveSheet.Cells(177, 1).PasteSpecial
logout
Application.ScreenUpdating = 0

On Error GoTo e:
Application.ScreenUpdating = 1
sk = Range("B209") ''''''' change skill number as required"
ImpDate1 = Range("B1")
Range("A210:W241").Select
Selection.ClearContents

Set cvsSrv = cvsApp.Servers(1) '(cvsApp.Servers.Count) '''''' we set a reference to the server here
Call doRep5("Historical\Designer\GI Skill Perf (I) ASA", sk, ImpDate1)
ThisWorkbook.ActiveSheet.Cells(210, 1).PasteSpecial
logout
Application.ScreenUpdating = 0

On Error GoTo e:
Application.ScreenUpdating = 1
sk = Range("B242") ''''''' change skill number as required"
ImpDate1 = Range("B1")
Range("A243:W273").Select
Selection.ClearContents

Set cvsSrv = cvsApp.Servers(1) '(cvsApp.Servers.Count) '''''' we set a reference to the server here
Call doRep5("Historical\Designer\GI Skill Perf (I) ASA", sk, ImpDate1)
ThisWorkbook.ActiveSheet.Cells(243, 1).PasteSpecial
logout
Application.ScreenUpdating = 0

On Error GoTo e:
Application.ScreenUpdating = 1
sk = Range("B275") ''''''' change skill number as required"
ImpDate1 = Range("B1")
Range("A276:W304").Select
Selection.ClearContents

Set cvsSrv = cvsApp.Servers(1) '(cvsApp.Servers.Count) '''''' we set a reference to the server here
Call doRep5("Historical\Designer\GI Skill Perf (I) ASA", sk, ImpDate1)
ThisWorkbook.ActiveSheet.Cells(276, 1).PasteSpecial
logout
Application.ScreenUpdating = 0

On Error GoTo e:
Application.ScreenUpdating = 1
sk = Range("B306") ''''''' change skill number as required"
ImpDate1 = Range("B1")
Range("A307:W336").Select
Selection.ClearContents

Set cvsSrv = cvsApp.Servers(1) '(cvsApp.Servers.Count) '''''' we set a reference to the server here
Call doRep5("Historical\Designer\GI Skill Perf (I) ASA", sk, ImpDate1)
ThisWorkbook.ActiveSheet.Cells(307, 1).PasteSpecial
logout
Application.ScreenUpdating = 0

On Error GoTo e:
Application.ScreenUpdating = 1
sk = Range("B340") ''''''' change skill number as required"
ImpDate1 = Range("B1")
Range("A341:W371").Select
Selection.ClearContents

Set cvsSrv = cvsApp.Servers(1) '(cvsApp.Servers.Count) '''''' we set a reference to the server here
Call doRep5("Historical\Designer\GI Skill Perf (I) ASA", sk, ImpDate1)
ThisWorkbook.ActiveSheet.Cells(341, 1).PasteSpecial
logout
Application.ScreenUpdating = 0

Exit Sub

e:
If Err.Number <> 91 Then
MsgBox Err.Number & " " & Err.Description
End If

End Sub


Sub doRep5(sReportName As String, ByVal sk As String, ByVal ImpDate As String)
Application.ScreenUpdating = False

ImpDate1 = Range("B1")

On Error Resume Next
cvsSrv.Reports.ACD = 1
Set Info = cvsSrv.Reports.Reports(sReportName)
If Info Is Nothing Then
If cvsSrv.Interactive Then
MsgBox "The Report " & sReportName & " was not found on ACD 1", vbCritical Or vbOKOnly, "CentreVu Supervisor"
Else
Set Log = CreateObject("ACSERR.cvslog")
Log.AutoLogWrite "The Report " & sReportName & " was not found on ACD 1"
Set Log = Nothing
End If
Else
B = cvsSrv.Reports.CreateReport(Info, Rep)
If B Then
Debug.Print Rep.SetProperty("Skill(s)", sk)
Debug.Print Rep.SetProperty("Interval(s)", "8-20")
Debug.Print Rep.SetProperty("Date", ImpDate1) 'Relative Date Cell Reference
B = Rep.ExportData("", 9, 0, False, False, True) 'this is for the report option
Rep.Quit
If Not cvsSrv.Interactive Then cvsSrv.ActiveTasks.Remove Rep.TaskID
Set Rep = Nothing
End If
End If

Set Info = Nothing



End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Maybe i missed it, but I don't see anything to paste. Also, I would use the actual sheet name instead of ActiveSheet, since the host workbook might not be the active workbook.
 
Last edited:
Upvote 0
Maybe i missed it, but I don't see anything to paste. Also, I would use the actual sheet name instead of ActiveSheet, since the host workbook might not be the active workbook.

I'll try the active sheet thing, it does copy, thats my bad i didnt paste the part of code that it copies.
 
Upvote 0

Forum statistics

Threads
1,215,727
Messages
6,126,520
Members
449,316
Latest member
sravya

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