Public Sub DemonstrateConvertions()
' https://www.mrexcel.com/board/threads/vba-convert-a1-reference-to-r1c1-reference.593703/
' Demonsterate conversion of addresses from A1 to R1C1 aand back)
Dim R As Range
Debug.Print "--- Convert Address ---"
Set R = ActiveSheet.Range("$E$90")
Debug.Print R.Address
Debug.Print "1. Address in A1 -> " & R.Address(ReferenceStyle:=xlA1)
Debug.Print "2. Address in R1C1 -> " & R.Address(ReferenceStyle:=xlR1C1)
Debug.Print "3. Convert R1C1 to A1 -> " & Range(Cells(90, 5), Cells(90, 5)).Address(ReferenceStyle:=xlA1)
Debug.Print "4. Convert A1 to R1C1 -> " & Range("E90").Address(ReferenceStyle:=xlR1C1) & vbCrLf
Dim R2 As Range
Set R2 = Range(Cells(90, 5).EntireColumn.Address)
Debug.Print R2.Address & " Defined using Range(Cells(90, 5).EntireColumn.Address)"
Debug.Print "5. Column Address in A1 -> " & R2.Address(ReferenceStyle:=xlA1)
Debug.Print "6. Column Address in R1C1 -> " & R2.Address(ReferenceStyle:=xlR1C1) & vbCrLf
Set R2 = Range(R.EntireColumn.Address)
Debug.Print R2.Address & " Defined using Range(Range.EntireColumn.Address)"
Debug.Print "7. Column Address in A1 -> " & R2.Address(ReferenceStyle:=xlA1)
Debug.Print "8. Column Address in A1 -> " & R2.Address(ReferenceStyle:=xlR1C1) & vbCrLf
Set R2 = Range(R.EntireRow.Address)
Debug.Print R2.Address; " Defined using Range(Range.EntireRow.Address)"
Debug.Print "9. Row Address in A1 -> " & R2.Address(ReferenceStyle:=xlA1)
Debug.Print "10. Row Address in A1 -> " & R2.Address(ReferenceStyle:=xlR1C1) & vbCrLf
Set R2 = Range(Cells(2, 8), Cells(17, 14))
Debug.Print R2.Address & " Defined using Range(Cells(2, 8), Cells(17, 14))"
Debug.Print "11. Address in A1 -> " & R2.Address(ReferenceStyle:=xlA1)
Debug.Print "12. Address in A1 -> " & R2.Address(ReferenceStyle:=xlR1C1) & vbCrLf
Debug.Print "--- Convert Formula ---"
Debug.Print "Formula defined using R.Formula = ""= F90 + G90 "" ... Or ..."
Debug.Print "R.Formula = ""=RC[1]+RC[2]"" Both produce identical results."
Debug.Print "NB: R.Address = " & R.Address
R.Formula = "=F90+G90"
Debug.Print "13. R.Formula >> " & R.Formula
Debug.Print "14. R.Formula2R1C1 >> " & R.Formula2R1C1
Debug.Print "15. R.Formula2R1C1Local >> " & R.Formula2R1C1Local & vbCrLf
Debug.Print "--- Using Application.Convert ---"
Debug.Print "16. " & Application.ConvertFormula( _
Formula:="=RC[1]+RC[2]", _
fromReferenceStyle:=xlR1C1, _
toReferenceStyle:=xlA1, _
ToAbsolute:=xlAbsolute, _
Relativeto:=R)
Debug.Print "17. " & Application.ConvertFormula( _
Formula:="=RC[1]+RC[2]", _
fromReferenceStyle:=xlR1C1, _
toReferenceStyle:=xlA1, _
ToAbsolute:=xlRelative, _
Relativeto:=R)
Debug.Print "18. " & Application.ConvertFormula("=f90+g90", xlA1, xlR1C1, xlAbsolute, R)
Debug.Print "19. " & Application.ConvertFormula("=f90+g90", xlA1, xlR1C1, xlRelative, R) & vbCrLf
Debug.Print "------ Demonstrate Overloading of Arguments in Range Function ----"
Debug.Print "20. Range(Cells(1, 1), Cells(3, 4)).Address = " & _
Range(Cells(1, 1), Cells(3, 4)).Address
Debug.Print "21. Range(Cells(1, 1).Address, Cells(3, 4).Address).Address = " & _
Range(Cells(1, 1).Address, Cells(3, 4).Address).Address
Debug.Print "22. Range(Cells(1, 1)).Address <--- **** RUNTIME ERROR ***"
Debug.Print "23. Range(Cells(1, 1).Address).Address <--- * OK * = " & _
Range(Cells(1, 1).Address).Address
End Sub