force calculation of row using VBA

nomadelement

New Member
Joined
Apr 26, 2012
Messages
14
Hello,

I am having some serious difficulty getting a row in my sheet to recalculate. I am using VBA to have check boxes hide and unhide rows, then a module to calculate the sum of only the visible rows. The problem is that once I click check boxes (hide / unhide rows) the formula to sum the visible rows will not recalculate and gives an error. I have tried all of the following VBA instructions inserted as the example below. The only instruction which works is "Application.CalculateFullRebuild" however this is a big sheet and that calculation takes a few minutes. I know there is apparently no way to calculate a full rebuild of a active sheet, so I am desperate for any ideas on how to get this a. active sheet. b. row. or c. individual cells to automatically fully recalculate everytime a checkbox is clicked.

Working (but not efficient) solution:

Private Sub CheckBox1_Click()
If CheckBox1 = True Then
[6:6].EntireRow.Hidden = False
Else: [6:6].EntireRow.Hidden = True
Application.CalculateFullRebuild (Application.CalculateFull also works)
End If
End Sub


Just in case it helps you the row i need updated is row 11 columns F:K
Other things I have tried and failed with:

ActiveSheet.calculate
Worksheet(1).Calculate
I have also tried many variations on instructions to calculate specific rows / columns, however I will not write everything just in case I did something wrong I still would like to hear your thoughts.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
This forces calculation of a specific range F11:K11. If the formulas within that range reference cells outside that range that also have formulas, those may have to be recalculated as well.

Also, the hide row 6 code was changed.

Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] CheckBox1_Click()
    Rows(6).Hidden = [color=darkblue]Not[/color] CheckBox1.Value
    Range("F11:K11").Calculate
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0
This forces calculation of a specific range F11:K11. If the formulas within that range reference cells outside that range that also have formulas, those may have to be recalculated as well.

Also, the hide row 6 code was changed.

Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] CheckBox1_Click()
    Rows(6).Hidden = [COLOR=darkblue]Not[/COLOR] CheckBox1.Value
    Range("F11:K11").Calculate
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]


Thank you for changing the check box code, that is much cleaner than what I was using. Unfortunately the cells are still not recalculating. The error message "#value" still shows.
 
Upvote 0
just for clarification, the only ways I can get the cells so far to update are to calculatefull the entire workbook which takes way too long, or to click on the text in the formula of that cell then press enter
 
Upvote 0
Are the cells F11:K11 and what's the formulas in each?


I ended up getting it working, heres what I did:

I used your code to hide the cells. I removed my module to create a formula which only calculates hidden cells and used a formula i didnt know before =subtotal(109,RANGE)

Everything now works perfectly!

Thank you for your help, you got me thinking in the right direction... stop making things more complicated than they need to be :)
 
Upvote 0
Good thing I totally skipped over the part where you said your had a module to calculate.
 
Upvote 0

Forum statistics

Threads
1,222,122
Messages
6,164,082
Members
451,871
Latest member
sanalytics

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