Solved

How to use Worksheet Change vs. Calculate event

Posted on 2009-07-09
5
1,333 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 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

729 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