Method 'Paste' of object '_Worksheet' failed

amer

New Member
Joined
Feb 8, 2005
Messages
1
Hi,

I get the error "Method 'Paste' of object '_Worksheet' failed" when I run the following macro.

Sub SaveVisible()
'
' SaveVisible Macro
' Macro recorded 2/8/2005 by amer
'

'
Cells.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Workbooks.Add
Cells.Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\amer\My Documents\abcd.txt", _
FileFormat:=xlText, CreateBackup:=False
End Sub

The purpose of the macro is to create a new excel file with the copied data from another file. I don not want to copy hidden rows and columns thus i copy only the visible data.

Could anyone please correct the macro or give a any other method of doing this kind of copy.

Thanks
Amer
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

tactps

Well-known Member
Joined
Jan 20, 2004
Messages
3,459
Change:
cells.select
to
[a1].Select

You are trying to paste into a range of a different size than the copy.
 

Zack Barresse

MrExcel MVP
Joined
Dec 9, 2003
Messages
10,881
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
Hello Amer, welcome to the board!


Excellent description!! You'd be surprised how many explanations are deficient and/or unrecognizable. Good job!

Maybe you can try something like this ...

Code:
Option Explicit

Sub SaveVisible()
    Dim thisWb As Workbook, thisWs, worksheet
    Dim newWb As Workbook, newWs As worksheet
    Set thisWb = ActiveWorkbook
    Set thisWs = thisWb.ActiveSheet
    Set newWb = Workbooks.Add(xlWBATWorksheet) 'only one sheet
    Set newWs = newWb.Sheets(1)
    thisWs.Cells.SpecialCells(xlCellTypeVisible).Copy newWs.Cells(1, 1)
    ActiveWorkbook.SaveAs Filename:= _
        "C:\Documents and Settings\amer\My Documents\abcd.txt", _
        FileFormat:=xlText, CreateBackup:=False
End Sub

Does this help?
 

Watch MrExcel Video

Forum statistics

Threads
1,123,318
Messages
5,600,921
Members
414,416
Latest member
Nobu

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
Top