ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel memory problem (https://www.excelbanter.com/excel-programming/284541-excel-memory-problem.html)

Valeria[_2_]

Excel memory problem
 
Dear Experts,
I have received a new computer some weeks ago and I am
trying to run my old macros on it.
I have a problem with one of these, though. It looks
pretty straightforward, the macro loops through one wbook,
compares one cell at a time to a range in a second wbook,
and when/if it finds a match it copies some cells from the
first wbook in the second.
The code that is giving me problems is:

Workbooks(before).Activate
Workbooks(before).Worksheets("before STAR").Range(Cells(i,
Blastqtitycolumn + 2), Cells(i, Blastpricecolumn)).Copy

I don't know why, it takes a lot of time and apparently
memory to perform this (even if the range consists of only
approx. 5 cells!), so much that the macro stops because of
lack of memory.

Do you know why this is happening and if I could somehow
modify my code to make the macro easier to run?

Many thanks!
Kind regards,
Valeria


shockley

Excel memory problem
 
Valeria,

Hard to say why this is happening without seeing the workbook, but you
might try changing your code to avoid having to activate the workbook and
avoid using the copy method. As long as you don't need the formatting of
the range that is being copied, this code will do the same job, will work
faster and just might get rid of the problem:

Set rng1 = Workbooks(before).Worksheets("before STAR") _
.Range(Cells(i, Blastqtitycolumn + 2), _
Cells(i, Blastpricecolumn))
Set rng2 = xxx 'Make rng2 the range you were pasting to
rng2.Value = rng1.Value

HTH,
Shockley



"Valeria" wrote in message
...
Dear Experts,
I have received a new computer some weeks ago and I am
trying to run my old macros on it.
I have a problem with one of these, though. It looks
pretty straightforward, the macro loops through one wbook,
compares one cell at a time to a range in a second wbook,
and when/if it finds a match it copies some cells from the
first wbook in the second.
The code that is giving me problems is:

Workbooks(before).Activate
Workbooks(before).Worksheets("before STAR").Range(Cells(i,
Blastqtitycolumn + 2), Cells(i, Blastpricecolumn)).Copy

I don't know why, it takes a lot of time and apparently
memory to perform this (even if the range consists of only
approx. 5 cells!), so much that the macro stops because of
lack of memory.

Do you know why this is happening and if I could somehow
modify my code to make the macro easier to run?

Many thanks!
Kind regards,
Valeria





All times are GMT +1. The time now is 11:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com