excel cannot complete this task with available resources - excel

When i'm trying to copy the data in one of the worksheets into new sheet using the below code in EXCEL 2007, WINDOWS 7, I'm facing with the error "excel cannot complete this task with available resources. choose Less data or close other applications".
when i close all other applications, its showing the same message. How to resolve this issue? Please advise.
With ActiveSheet
.Range("A1").Select
.UsedRange.SpecialCells(xlCellTypeVisible).Copy
End With
With ThisWorkbook
Set ws = .Worksheets.Add(After:=.Sheets(.Sheets.count))
NewSheet = ActiveSheet.Name
End With
With ActiveSheet
.Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteColumnWidths
Selection.PasteSpecial xlPasteAll
.Range("A1").Select
End With
When i save the xls as .xls (97-2003) its working fine. But i want to run with more data than 65k

I tested your code on a newly created excel document and copied 80K rows to a new sheet.
Your code works...
I did however create it as a macro sub routine and run it multiple times to check.
But you said you saved your document once as a xls. Maybe you got the limitations with it also.
Please and create a new excel document and always save it as xlsx...

Related

Excel Macro wont Paste only when sheet is protected **even though code unprotects sheet**

Company I'm working with keeps daily operational data in individual Excel files. I've created coding in another Excel file (I'll call it the log file) which does the following:
Runs code to extract important data from daily file based on date in file name. Data is in multiple tabs.
Pastes data into two different tabs in log file.
Creates charts and additional metrics
All log file tabs are protected (no password) to prevent accidental changes and code unprotects and protects as needed. Similar code executes multiple times without problem but errors when pasting on one particular sheet. Code where problem is:
' gets most recent data for dashboard
Windows(filename3).Activate
Sheets("Production - Mill A & Planer").Select
Range("A1:C29").Select
Selection.Copy
Windows("Consolidated Morning Reports r26.xlsm").Activate
Sheets("dashboard").Select
Call m24_unprotect_sheet
Range("A1").Select
ActiveSheet.Paste '<- PROBLEM IS HERE
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
I get an error (Run time error 1004: Paste method of worksheet class failed) and debugger shows it happens at the command ActiveSheet.Paste. If the sheet is unprotected, the code works as intended. The error happens only if the sheet is protected and not if it is unprotected, despite the unprotect sheet code unprotecting the sheet. I can confirm that after the code stops, the sheet is unprotected. If I re-run the code, it will work since I assume the sheet is now unprotected. I have nearly identical code executing on other sheets without this problem.
I've tried protecting and unprotecting at different locations in the code. I also tried changing the property of the cells where the paste should occur to unlocked but did not fix the problem.

Error trying to save Excel worksheet as CSV via Excel VBA macro

Using Excel 2010 on Windows 7. I have a VBA macro that saves the first worksheet of an excel workbook (.xlsm) into a CSV file. This had mostly worked in the past. Recently, I get error messages per the picture below, which state "Run-time error '1004': Microsoft Excel cannot open or save any more documents because there is not enough available memory or disk space."
So a couple things:
A common suggested solution from my Google searching is to set the file's location as a Trusted Location. This did not work.
I have enough disk space. That can't be the issue.
I'm not sure exactly what is meant by "available memory," but if it in any way refers to the Physical Memory figure listed in Windows Task Manager, that figure is 75%. The ultimate CSV file itself tends to be about 1,500KB.
I am always able to save this worksheet as a CSV manually without encountering any error messages, but when I do it via this VBA macro, I get the error message.
Picture of error message
My excel VBA save-as-CSV macro:
Sub saveAsCSV()
Application.DisplayAlerts = False
ThisWorkbook.Sheets("Sheet1").Copy
ActiveWorkbook.SaveAs Filename:="dummyfilename.csv", FileFormat:=xlCSV, CreateBackup:=True
ActiveWorkbook.Close
Application.DisplayAlerts = True
End Sub
Try this, you don't have to use Copy or Activate. If your code is in the workbook that you want to save as a workbook you can use ThisWorkbook. Kudos to #Variatus for identifying need for a path.
ThisWorkbook.Sheets("Sheet1").SaveAs ThisWorkbook.Path & "/" & "dummyfilename" & ".csv", FileFormat:=6

Create a workbook using a macro with no formulas, but still linked back to macro workbook?

So I built this macro workbook that creates a formatted monthly report for me.
How it works is the macro builds the report based on some criteria I define, then it copies the data portion from the worksheet "Slide" and pastes it as values to the next worksheet, "Deliverable", using this code:
Application.Goto (ActiveWorkbook.Sheets("Slide").Range("A1"))
Range("C2", Cells(TableRows, 30)).Select
Selection.Copy
ActiveSheet.Next.Select
ActiveSheet.Paste
then it formats and sorts everything on "Deliverable", and copies it to a new workbook using this:
Sheets("Deliverable").Select
Sheets("Deliverable").Copy
The only issue is when you open up the new workbook that only contains the copy of "Deliverable", it's still linked back to the original macro workbook and you get the security warning. I could care less about this as I know it came from me, but the report is shared outside my organization and I would prefer to avoid questions and/or hassles for my clients.
The new workbook is not macro enabled, and like I said above, contains no formulas, let alone those that reference the original workbook.
What can I do to address this?
OK, the links were being caused by named ranges in the workbook that came over with the copied worksheet. No formulas, just named ranges.
I added this after the worksheet copy and it took care of it.
Dim nm As Name
On Error Resume Next
For Each nm In ActiveWorkbook.Names
nm.Delete
Next
On Error Goto 0

Excel VBA Error "The picture is too large and will be truncated" when closing file

I have been working on this project for a long time and am suddenly getting a new error whenever I close my Excel file. I get the error twice "The picture is too large and will be truncated." There is no picture in my file. I am pasting formats.
This seems to be one of the Excel "Unsolved Mysteries".
I am using MS Office Professional Plus 2010 on Windows 7.
I have researched this and tried the following:
Deleted all %temp% files
Ran CCleaner
Set CutCopyMode =
False after all paste special (formats)
Went to add/remove
programs and reconfigured Office to stop the Clip Organizer from
running. (Control Panel\Programs\Programs and Features -> MS Office
Professional Plus 2010 -> Change -> Add or Remove Features -> Office
Shared Features -> Clip Organizer -> Not Available, etc.)
Rebooted
None of that helped, so I narrowed down the source of the problem by commenting out function and subroutine calls, running the program, saving and then pressing "x" to close. I did this until I found the right sub. Then I commented out all the lines of the sub and added them back in one logical chunk at a time until I found the problem area. Here it is:
' *********** APPLY BASIC ROW FORMATTING FROM TEMPLATE ***********
' Copy basic row formatting from template and paste over all rows
wksTemplate.Rows(giHEADER_ROW + 1).Copy
myWS.Rows(lFirstRow & ":" & lLastRow).PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
The paste contains formatting only - colors, borders, number formats, wrapping etc. It probably pastes on a range of 200 rows on average.
I have not changed these 3 lines of code in months. Why now?
Has anyone solved this mystery?
Thanks,
Shari
I got this error after copying a range and then using a set of pastespecial calls:
.PasteSpecial xlPasteColumnWidths
.PasteSpecial xlPasteValuesAndNumberFormats
.PasteSpecial xlPasteFormats
solution was to copy an empty cell and pastespecial xlvalues back into itself:
' to avoid the message on closing the book - "picture is too large and will be truncated", copy and paste a singe empty cell
ThisWorkbook.Worksheets(1).Cells(1, 1).Copy
ThisWorkbook.Worksheets(1).Cells(1, 1).PasteSpecial xlValues
' clear clipboard
Application.CutCopyMode = False
I sometimes have the same problem as you, but i have many pictures in my files...
Also sometimes i have slow down (open/close or just standard calculations(menu popup...)).
Usually when i close the workbook, and reopen it, it works fine again.
I have maybe some answer, not sure if any help :
Do you use Global variables ?
for example, in module 1:
Option Explicit
Public BigObject as AnyBigSizeType
Sub xxx() 'code following
try to avoid using global variables, usually its a mess and not even usefull.
Also, just to be safe, try in the immediate window : activesheet.pictures.delete
(or even activesheet.shapes.delete , but this one also deletes comments and other stuff...)
I get the error when closing a file after a macro used the Range.Copy command, even if the clipboard is empty. Doing Application.CutCopyMode = False is not enough, but adding this at the end of macros that use the Range.Copy method seems to be the solution:
This is my solution:
'without this it will say "The image will be truncated because it's too large", because Excel is stupid
[A1].Copy
Application.CutCopyMode = False

Run Time Error '1004': Select method of Range Class failed VBA 2003

I am trying to copy a column from one sheet to another. The code I am using is a recorded macro and it works fine until I connect it to a button. When I do so, it gives a
Run Time Error '1004': Select method of Range Class failed
Here is the code and I can see nothing wrong with it. When I hit debug it highlights the second line.
Sheets("Count").Select
Columns("C:C").Select
Selection.Copy
Sheets("Add Invintory").Select
Range("b1").Select
ActiveSheet.Paste
Sheets("Count").Select
Sheets("Count").Columns("A:A").Select
Columns("A:A").Select
Selection.Copy
Sheets("Add Invintory").Select
Range("A1").Select
ActiveSheet.Paste
I have no clue what the problem is. Please help
You should always avoid using .Select They are a major cause of errors. You may want to see How to avoid using Select in Excel VBA
Sub Sample()
Sheets("Count").Columns("C:C").Copy _
Sheets("Add Invintory").Columns("B:B")
Sheets("Count").Columns("A:A").Copy _
Sheets("Add Invintory").Columns("A:A")
End Sub
I think the issue is that you have written the code in another sheet's code module. If I'm in Sheet1, and write e.g.
Sheets("Sheet2").Select
Columns("A:A").Select
...then Excel assumes you are referring to the Columns on Sheet1 as it treats the current sheet as a default. Therefore, you've told Excel "select Sheet 2" then "select a column on Sheet 1"...which it can't do so it gives you an error message. The best solution would be not to use 'Select'...but you will still see in Siddharth's code that he has had to refer to sheet addresses explicitly
Your original code would have worked if placed in the ThisWorkbook module. Locations for entering code are explained towards the end of this Excel help video
When you are putting vba code into the "view sheet code" .. There definitely helps to use Application.Run ... to run macro..
I had problem i directly input macro to sheet code.. for selection in another sheet it claimed runtime error 1004.. So i created macro separately and then i put Application.Run my macro from sheet code.
Works out perfectly ;)
This Application.Run also helps when you have too big macro that excel claim it cant be so big. You can easily divide to several parts and then just run applications one by one.. ;)

Resources