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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

BarryL

Well-known Member
Joined
Jan 20, 2014
Messages
1,436
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
by custom functions do you mean UDF's? if so try put the below in the UDF code.

Code:
Application.Volatile
 

MuppetReaper

New Member
Joined
Jun 14, 2013
Messages
30
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:

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,957
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Changing the height of rows or width of columns doesn't cause a recalculation so Application.Volatile will have no effect.
 

MuppetReaper

New Member
Joined
Jun 14, 2013
Messages
30
OK, so is there any way to make it recalc those cells without it clearing the clipboard?
 

Watch MrExcel Video

Forum statistics

Threads
1,133,530
Messages
5,659,355
Members
418,498
Latest member
nattynat

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
Top