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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
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,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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