confusion123
Active Member
- Joined
- Jul 27, 2014
- Messages
- 400
Cell A1 of Sheet2 has a value of 1.
If I type in cell A1 of Sheet1:
I get a value of 100, as expected because of the code below:
However, if I change the value in cell A1 of Sheet2 to 2, I expected the value in cell A1 of Sheet1 to be 2000 AUTOMATICALLY but it doesn't. Instead, I have to manually type into cell A1 of Sheet1:
then it returns a value of 2000.
I assume this is the normal behaviour of a user-defined function?
My workaround is to add the following event in Sheet1:
Is this OK or is there a better solution, such as an event that when Sheet1 is activated, all formulae in Sheet1 are updated?
Thanks
If I type in cell A1 of Sheet1:
Code:
=MyFn()
I get a value of 100, as expected because of the code below:
Code:
Option Explicit
Function MyFn() As Double
Select Case Sheet2.Cells(1, 1).Value
Case 1
MyFn = 100
Case 2
MyFn = 2000
Case Else
MyFn = 30000
End Select
End Function
However, if I change the value in cell A1 of Sheet2 to 2, I expected the value in cell A1 of Sheet1 to be 2000 AUTOMATICALLY but it doesn't. Instead, I have to manually type into cell A1 of Sheet1:
Code:
= MyFn()
then it returns a value of 2000.
I assume this is the normal behaviour of a user-defined function?
My workaround is to add the following event in Sheet1:
Code:
Option Explicit
Private Sub Worksheet_Activate()
Me.Cells(1, 1).Formula = Me.Cells(1, 1).Formula
End Sub
Is this OK or is there a better solution, such as an event that when Sheet1 is activated, all formulae in Sheet1 are updated?
Thanks
Last edited: