Solved

How to use Worksheet Change vs. Calculate event

Posted on 2009-07-09
5
1,315 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Excel formula 5 52
message box in access 4 33
how to compare 2 PST files? 3 57
using web browser with BING 40 86
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now