In this file, we have explained how BREF and BYval are different. By ref can change their value from another program
‘By Val cannot change their value from other programs Please use immediate window to understand this code.

Sub CallingProcedure()
        Dim A As Long
        Dim B As Long
        A = 123
        B = 456
        Debug.Print "BEFORE CALL = A: " & CStr(A), "B: " & CStr(B)
        CalledProcedure X:=A, Y:=B
        Debug.Print "AFTER CALL =  A: " & CStr(A), "B: " & CStr(B)
    End Sub
    Sub CalledProcedure(ByRef X As Long, ByVal Y As Long)
        X = 321
        Y = 654
    End Sub

Sub CallingProcedure()
        Dim Range1 As Range
        Dim Range2 As Range
        Set Range1 = Range("A1")
        Set Range2 = Range("A2")
        Range1.Value = 123
        Range2.Value = 456
        '''''''''''''''
        ' Debug Group 1
        '''''''''''''''
        Debug.Print "BEFORE CALL::Range1: " & Range1.Address(False, False) & " = " & Range1.Value
        Debug.Print "BEFORE CALL::Range2: " & Range2.Address(False, False) & " = " & Range2.Value
        CalledProcedure R1:=Range1, R2:=Range2
        '''''''''''''''
        ' Debug Group 2
        '''''''''''''''
        Debug.Print "AFTER  CALL::Range1: " & Range1.Address(False, False) & " = " & Range1.Value
        Debug.Print "AFTER  CALL::Range2: " & Range2.Address(False, False) & " = " & Range2.Value
    End Sub
    
    Sub CalledProcedure(ByRef R1 As Range, ByVal R2 As Range)
        R1.Value = 321
        R2.Value = 654
        
        Set R1 = Range("A3")
        Set R2 = Range("A4")
    End Sub