Solved

How to use Worksheet Change vs. Calculate event

Posted on 2009-07-09
5
1,322 Views
Last Modified: 2013-11-25
BACKGROUND:
I have found a way to copy cell values from one sheet to another sheet so I can access PREVIOUS cell values.  But using the CHANGE event does not copy the results from formulas.  MSDN says there is a Calculate event, but it does not have the range stuff and I'm not sure how to use it.

QUESTION: How can I copy the formula results from a sheet to another location for reference later, AND REMEMBER WHAT THEY WERE AFTER ONE RECALCULATION?

This will then be used with conditional logic: If my new formula result is > than last result, then do something.  If not, do something else.

Thanks in advance for any help.

SetOldSheet.xls
0
Comment
Question by:DWG123
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:Devom
ID: 24814336
Using the calculate event you can see when a worksheet is calculated (and when automatic calculation is turned on this pretty much guarantees you'll see whenever it changes).  However you cannot see which parts of the sheet actually changed.

If you are only looking at one specific cell, or set of cells, try always keeping a copy of them in another location, then every time the calculate event is triggered do your check.

The calculate event is very touchy and will get triggered every time something in the application is changed if you have any volatile functions i.e. today(), now(), CELL(...) on your worksheet of interest so keep that in mind
0
 
LVL 3

Accepted Solution

by:
Devom earned 500 total points
ID: 24814537
Didn't notice you attached a spreadsheet.  I put in a function for the calculation method, but it is memory intensive (and will only work if every cell is involved in a formula somehow).  You can certainly pare it down a bit if you know something about the range you're looking at.

If this is going to be the final layout of your sheet, I'd recommend the resize function (check out how I changed the commented chunk of code)
SetOldSheet.xls
0
 

Author Comment

by:DWG123
ID: 24821000
Devom,

Thank you.  This copies the formula results beatifully.  :-)

When I tried to close the spreadsheet it wanted to recalc before closing and got stuck in a loop.  How do you get out of that (aside from break)?

Would it be better to change the Me.Range to something like ("A1:C20","E1:G20") or to use the Resize(1,20)?

Does the resize tell the computer not to worry about the rest of the sheet and save processing time?

0
 
LVL 3

Expert Comment

by:Devom
ID: 24823555
Infinite loops when dealing with excel events usually mean that the event is triggering itself, though that usually crashes excel.  You can avoid that error by turning off and on application.enableevents.

You're not going to notice a big difference in performance using resize vs defining the range, but a defined range (i.e Me.Range("A1:C20")) should be marginally faster and improves readability.  You really only want to use resize when you don't know the size of your range beforehand.  Both tell the computer to only worry about a certain section of the sheet.
0
 

Author Closing Comment

by:DWG123
ID: 31601473
Thank you for the workable solution, explanation and answers to my follow up question.  I was about to pull out my last few grey hairs until you helped!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question