Custom VBA Function

kland1

New Member
Joined
Mar 18, 2009
Messages
12
I created a custom function in vba but it does not update automatically like sum or other functions. The function gets numbers from another worksheet in the same workbook but when the numbers on the other worksheet change the cell with the function does not update automatically. Is there any special code that I need to have it update when the number changes on the other worksheet?
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hello and welcome to MrExcel.

Try adding this near the top of your function

Code:
Application.Volatile
 
Upvote 0
Hey guys,

That line of code works good but its doing something different now. The cells update automatically now but since i just the same function in multiple workbooks, it seems that only one workbook will show the values and the other ones will say #VALUE!. I can only see the values of the other workbook when i click on a cell and hit enter. This is when the other workbook will change to #VALUE!. Is there a way I can fix this?
 
Upvote 0
'*********************************************************************************************
' Retrieves the number of copper ports
' checkRange - the range to check for "Copper"
' numberCol - the number of columns right of checkRange to retrieve the data
Function CountCopper(checkRange As range, numberCol) As Integer
Application.Volatile
total = 0
Col = checkRange.Column + numberCol

For Each cell In checkRange
If (LCase(cell.Value) = "copper") Then
Row = cell.Row
total = total + Sheets(checkRange.Worksheet.Name).Cells(Row, Col).Value
End If
Next cell

CountCopper = total
End Function
 
Upvote 0
Instead of:

total = total + Sheets(checkRange.Worksheet.Name).Cells(Row, Col).Value

try:

total = total + checkRange.Parent.Cells(Row, Col).Value
 
Upvote 0

Forum statistics

Threads
1,214,870
Messages
6,122,019
Members
449,060
Latest member
LinusJE

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