Recalc custom function automatically

MuppetReaper

New Member
Joined
Jun 14, 2013
Messages
30
bit of a strange one here!
I have a sheet that has some custom functions to calculate the total height and width of a range, but it does't recalc automatically if you adjust the size of the row/column.
So I added code to each sheet to recalc when a cell is clicked -
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Calculate
End Sub
but this seems to stop the user being able to use copy and paste on the sheet, as it seems to clear the clipboard when the new cell is selected.
So, I've had to add a couple of buttons to turn this on and off
Code:
Sub UpdatesOff()
    Application.EnableEvents = False
End Sub
Sub UpdatesOn()
    Application.EnableEvents = True
End Sub

But is there any other way around this? it seems daft to have to do this

thanks
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
by custom functions do you mean UDF's? if so try put the below in the UDF code.

Code:
Application.Volatile
 
Upvote 0
this is the function (I didn't write it)
Code:
Public Function COLWIDCOUNT(TgtCells As Range)
Application.Volatile True
No_of_Cols = TgtCells.Columns.Count
ColWidSubtotal = 0
For Lp1 = 1 To No_of_Cols
ColWidSubtotal = ColWidSubtotal + TgtCells.Cells(1, Lp1).ColumnWidth
Next Lp1
COLWIDCOUNT = ColWidSubtotal
End Function
Public Function ROWHGTCOUNT(TgtCells As Range)
Application.Volatile True
No_of_Rows = TgtCells.Rows.Count
RowHeightSubtotal = 0
For Lp1 = 1 To No_of_Rows
RowHeightSubtotal = RowHeightSubtotal + TgtCells.Cells(Lp1, 1).RowHeight
Next Lp1
ROWHGTCOUNT = RowHeightSubtotal
End Function
 
Last edited by a moderator:
Upvote 0
Changing the height of rows or width of columns doesn't cause a recalculation so Application.Volatile will have no effect.
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,323
Members
449,077
Latest member
jmsotelo

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