Copy/PasteValues Run-time error '1004': Application-defined or object-defined error

N00bTube

New Member
Joined
Aug 10, 2015
Messages
6
Hi!

Working on a code to convert a part of a sheet into a CSV file:

Problem is that I get "Run-time error '1004': Application-defined or object-defined error" when running it, stopping at "ActiveSheet.PasteSpecial Paste:=xlPasteValues".

Any help? :)


Code:
Sub ProdCSV()

Sheets("EM_S.06.03").Activate
'Teller antall instrumenter
nyttantall = WorksheetFunction.CountA(Range(Cells(16, 2), Cells(2000, 2)))

A30kol = WorksheetFunction.Match("C0060", Range(Cells(15, 1), Cells(15, 75)), 0)

LocationPath = Application.ThisWorkbook.Path & "\"
Filnavn11 = Range("Year2").Value & " Solvency II S.06.03.csv"
Filnavn22 = Range("Year2").Value & " Solvency II S.09.01.csv"

Filnavn1 = LocationPath & Filnavn11
Filnavn2 = LocationPath & Filnavn22

Sheets("EM_S.06.03").Range(Cells(15, 2), Cells(15 + nyttantall, A30kol)).Select
Selection.Copy
    Workbooks.Add
    ActiveSheet.PasteSpecial Paste:=xlPasteValues
    ActiveWorkbook.SaveAs Filename:=Filnavn1, FileFormat:=xlCSV, CreateBackup:=False
    Application.DisplayAlerts = False
    ActiveWorkbook.Close
    Application.DisplayAlerts = True
    
Sheets("EM_S.09.01").Activate
Sheets("EM_S.09.01").Range(Cells(15, 2), Cells(18, 9)).Select
Selection.Copy
    Workbooks.Add
    ActiveSheet.PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    ActiveWorkbook.SaveAs Filename:=Filnavn2, FileFormat:=xlCSV, CreateBackup:=False
    Application.DisplayAlerts = False
    ActiveWorkbook.Close
    Application.DisplayAlerts = True

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
you might try giving it the cell you want it to paste to.

Code:
ActiveWorkbook.ActiveSheet.Range("A1").PasteSpecial Paste:=xlPasteValues
 
Upvote 0

Forum statistics

Threads
1,215,852
Messages
6,127,322
Members
449,374
Latest member
analystvar

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