Auto-update (calculate) the Excel sheet when a cell is changed

cercig

New Member
Joined
Aug 24, 2015
Messages
8
I am using Excel 2010 and I want that the Excel sheet will be updated (calculated) automatically when the value of a cell (<code style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: pre-wrap; background-color: rgb(238, 238, 238);">Range("B7")</code>) is changed (The <code style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: pre-wrap; background-color: rgb(238, 238, 238);">Range("B7")</code> is a drop-down list). I am trying to use the intersect-target method like:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">Private Sub Worksheet_Change(ByVal target As Range)
If Not Intersect(target, Range("B7")) Is Nothing Then
ActiveSheet
.Calculate
End If
End Sub</code>I have two questions about this:
Does it matter if I put this Private Sub under any module? Or am I supposed to write it in the exact sheet under the Microsoft Excel -object menu in VBA?
The second question is how I can make this work? The sheet doesn't update (calculate) automatically when I change the <code style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: pre-wrap; background-color: rgb(238, 238, 238);">Range("B7")</code>. It only updates when I save the Excel file.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I am using Excel 2010 and I want that the Excel sheet will be updated (calculated) automatically when the value of a cell (<code style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: pre-wrap; background-color: rgb(238, 238, 238);">Range("B7")</code>) is changed (The <code style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: pre-wrap; background-color: rgb(238, 238, 238);">Range("B7")</code> is a drop-down list). I am trying to use the intersect-target method like:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">PrivateSub Worksheet_Change(ByVal target As Range)
IfNot Intersect(target, Range("B7"))IsNothingThen
ActiveSheet
.Calculate
EndIf
EndSub</code>I have two questions about this:
Does it matter if I put this Private Sub under any module? Or am I supposed to write it in the exact sheet under the Microsoft Excel -object menu in VBA?
The second question is how I can make this work? The sheet doesn't update (calculate) automatically when I change the <code style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: pre-wrap; background-color: rgb(238, 238, 238);">Range("B7")</code>. It only updates when I save the Excel file.
Hi cercig,

In order for this to work you need to add the code directly to the back end of the sheet in question, so if you want Sheet2 to recalculate when B7 of Sheet2 is updated or changed, right-click on the tab name of Sheet2 and select View Code. It is in this window that you need to paste your code.

Doing so should answer both of your questions above.

Finally, don't forget to ensure the syntax you use is correct (there appear to be a lot of missing spaces in your code)

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B7")) Is Nothing Then
ActiveSheet.Calculate
End If
End Sub
 
Upvote 0
Hi cercig,

In order for this to work you need to add the code directly to the back end of the sheet in question, so if you want Sheet2 to recalculate when B7 of Sheet2 is updated or changed, right-click on the tab name of Sheet2 and select View Code. It is in this window that you need to paste your code.

Doing so should answer both of your questions above.

Finally, don't forget to ensure the syntax you use is correct (there appear to be a lot of missing spaces in your code)

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B7")) Is Nothing Then
ActiveSheet.Calculate
End If
End Sub

@fishboy Thanks for the tips. I also realized that calculation inside the Excel menu is adjusted to "Manual Calculation". That's why my sheet did't update even if I tried inside the VBA code.
 
Upvote 0
@fishboy Thanks for the tips. I also realized that calculation inside the Excel menu is adjusted to "Manual Calculation". That's why my sheet did't update even if I tried inside the VBA code.
You're welcome. Glad to hear you got it sorted.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top