rvphx
rvphx

Reputation: 2402

Excel VBA Error while pasting data to new sheet

I am pasting below the piece of code which picks up only the visible rows and pastes it to a new sheet for some more processing. However when it tries to paste, it fails with the error that "Excel cannot complete the operation with the resources. Please close some programs or try later". Any alternative to this code? BTW, this is excel 2007.

Function createSummary()
    ActiveSheet.Outline.ShowLevels RowLevels:=2
    Cells.Select
    Selection.SpecialCells(xlCellTypeVisible).Select
    Application.CutCopyMode = False
    Selection.Copy

    Worksheets.Add().Name = "Summary"
    ActiveSheet.Paste
    Cells.Font.Bold = False

    Columns("A").Insert

Upvotes: 0

Views: 1457

Answers (1)

Reafidy
Reafidy

Reputation: 8431

Without seeing your workbook it looks as though you are having some sort of memory issues.

You don't need to select cells to work with them. Try something like this:

With ActiveSheet
    .Outline.ShowLevels RowLevels:=2
    .UsedRange.SpecialCells(xlCellTypeVisible).Copy Worksheets.Add().[A1]
End With

With ActiveSheet
    .Name = "Summary"
    .UsedRange.Cells.Font.Bold = False
    .Columns("A").Insert
End With

Upvotes: 2

Related Questions