I have a sheet in Excel with cells that uses this VBA macro (using two parameters, it count the number of occurrence of arg#1 in the range of Arg#2 accross all sheets, and return the total count):
Public Function WBCountString(SearchFor As String, InRange As Range) As Long
Dim wbcs As Long, rng As Range, addr As String
For Each s In Worksheets
addr = InRange.Address
Set rng = s.Range(addr)
wbcs = wbcs + Application.WorksheetFunction.CountIf(rng, SearchFor)
Next s
WBCountString = wbcs
End Function
The macro is used as a function in a cell as shown below, which uses cells located in A:A as parameters:
When I change a A:A cell value, the value of the cell that uses the script do not change, and I have to click on the formula and press "Enter" for the value to be updated.
I tried using this function in "ThisWorkbook", I get a "Change" message box but the cells in F:F do not update or change value:
Private Sub Workbook_SheetChange(ByVal Sh As Object, _
ByVal Source As Range)
' runs when a sheet is changed
MsgBox "Change."
Application.Calculate
End Sub
How can I make so that the cells that uses this macro updates every time any of the cells A:A on any of the sheet of the workbook are updated?
Workbook_SheetChange
event. – BigBen