Assigning F9 or shiftF9 to a macro

rob1987

New Member
Joined
Feb 14, 2011
Messages
39
Hello,

I have the bulk of my code sorted but I am just missing the last detail. In Sheet2 I have columns of data, split into ranges by month name, Feb and March . In the last column, T, I have the total of the values within each row. Simple so far. In the sheet Overview I have two checkboxes to hide and unhide the month ranges, one with the macro:

Code:
Range("Feb").EntireColumn.Hidden = Not Range("Feb").EntireColumn.Hidden

and the second with the same thing for the March range.

I then want T to update to show the values for only the non hidden rows. To do this I entered the following code into the sheet module:

Code:
Public Function SumVisible(myRng As Range)
Dim myCell As Range, mySum As Double
Application.Volatile
For Each myCell In myRng
    If myCell.ColumnWidth <> 0 Then mySum = mySum + myCell.Value
Next myCell
SumVisible = mySum
End Function

and in column T used the =SumVisible(f3:m3) forumla which works fine. My only issue is that I need to press f9 each time I use my check boxes to hide/unhide the ranges. Is there anything I can build into my code anywhere to automatically calculate the new total whenever I use the checkboxes?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
In the last line of the macro, you could add (after hiding or unhiding the column)

Code:
Columns("T").Calculate

Then you could remove the Application.Volatile from the UDF.
 
Upvote 0
Thank you all for your replies.

I tried Andrew's recommendation as the first one and it has worked perfectly, so thank you for that, but thanks all for your recommendations.
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,153
Members
452,891
Latest member
JUSTOUTOFMYREACH

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