Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50321

How to trap formula calculations (using Worksheet_Calculate() ?)

$
0
0
This may be a stupid question, but I don't know how to use Worksheet_Calculate() in vba. Sample code:
Code:

Private Sub Workbook_Open()
Application.Calculation = xlAutomatic
Sheets("Sheet1").Protect UserInterfaceOnly:=True, AllowSorting:=True, AllowFiltering:=True
End Sub

Code:

Private Sub Worksheet_Calculate() '//where chkVarB, chkVarC, chkVarD are variables that control when to do the calculation
Select Case True                  '//trap for which cell is being calculated
    Case [B2]: If chkVarB = True Then doDefault Else Cancel = True  '//I know "doDefault" and "Cancel = True" are
    Case [C2]: If chkVarC = True Then doDefault Else Cancel = True  '//not correct, but I dont know the correct syntax
    Case [D2]: If chkVarD = True Then doDefault Else Cancel = True
    Case Else: Cancel = True
End Select
End Sub

The above code is bogus, its just an example of what I need to accomplish. Because of some vba code for a table, I must open my worksheet with page Calculation Options set to "Automatic". But since there are thousands of formulas in the sheet I must control their updating (because of the very long time it would take to re-calculate all the sheet at one time). Always the number of formulas that will be needed to be updated (at one time) will only be a few dozen or less. I do not know if Sub Worksheet_Calculate() is where I need to code, I'm only guessing. Can someone kindly offer a hand, I've worked on this for weeks & dont know how to do it. Thanks so much

Viewing all articles
Browse latest Browse all 50321

Latest Images

Trending Articles



Latest Images