?
Solved

How to use Worksheet Change vs. Calculate event

Posted on 2009-07-09
5
Medium Priority
?
1,335 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

770 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