I am passing a parameter by reference but it is not changing in the way that I would expect. I set it to 16.1, pass it to a subroutine by reference which should lead to its value changing to 42.42 but this does not happen. What am I doing wrong? I am working in Excel 2013.
Sub AdjustANumber(ByRef a As Double)
a = 42.42
Dim a As Double
a = 16.1
' Here the debugger tells me a = 16.1. This is correct.
' Here the debugger tells me a = 16.1 but I expected a = 42.42 since it was passed by reference to the AdjustAnumber subroutine.
MsgBox a ' This MsgBox displays 16.1 which is incorrect
This seems to be in agreement with this:
Maybe I didn't configure my *.xlsm file to allow passing by reference? The above code is defined in Modules->Module1 of my Excel file.