I\'ve tried to attempt something that was answered by JaredPar ByRef vs ByVal Clarification
ByVal
in VB.NET means that a copy of the provided
I would do it this way.
Sub test1()
Dim trythis As Boolean
trythis = False
If (Sheets("TESTING").Range("A1").value = 1) Then
tr = testingRoutine(trythis)
If tr Then
Debug.Print "Value changed to 0"
Sheets("TESTING").Range("A1").value = 0
End If
End If
End Sub
Private Function testingRoutine(ByRef trythis As Boolean)
Debug.Print "Ran Function"
testingRoutine = True
End Function
Because trythis
is not a global variable, changing it in the function will do nothing in the sub. It will just define trythis
as True in the function and stay in that scope. To get trythis
to be affected by the function and read by the sub you have to assign it to a variable within the sub.