Article ID: 172760
Article Last Modified on 10/10/2006
Function Test()
Application.Volatile
' Returns the cell one column to the left of the active cell. Note
' that the active cell is not necessarily the cell that is calling
' the function.
Test = ActiveCell.Offset(0, -1).Value
End Function
change it to the following:
Function Test()
Application.Volatile
' Returns the cell one column to the left of the cell that is
' actually calling the function.
Test = Application.Caller.Offset(0, -1).Value
End Function
When you do this, the function correctly uses the cell that is calling the function instead of using the currently active cell.
A1: 1
A2: 2
A3: 3
A4: 4
A5: 5
Function Test()
Application.Volatile
Test = ActiveCell.Offset(0, -1).Value
End Function
=Test()
Note that the formula returns the value 1. This is the correct value
because the cell that is one column to the left of the active cell (B1)
contains the value 1.
Function Test()
Application.Volatile
Test = Application.Caller.Offset(0, -1).Value
End Function
When you change the function, and then recalculate the worksheet, the
formulas in B1:B5 return the values 1 through 5 no matter what cell or worksheet is active.163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: XL5 XL7 XL97 XL98 XL
Keywords: kbdtacode kbprb kbprogramming KB172760