View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions,microsoft.public.excel.misc,microsoft.public.excel.programming
Don Guillett Don Guillett is offline
external usenet poster
 
Posts: 10,124
Default Question on this conversion code switching between r1c1 to A1 format tia sal2

Did you place the code into a regular (not sheet module)


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"temp" wrote in message
...
Greets All

I found this code on the web but I'm having problems getting it to work
when I type in '=R1C1Converter(R1C2) I get an error
message and I don't know why?

Tia sal2


Function R1C1converter(Address As String, Optional R1C1_output As Integer,
Optional RefCell As Range) As String
'Converts input address to either A1 or R1C1 style reference relative
to RefCell
'If R1C1_output is xlR1C1, then result is R1C1 style reference.
'If R1C1_output is xlA1 (or missing), then return A1 style reference.
'If RefCell is missing, then the address is relative to the active
cell
'If there is an error in conversion, the function returns the input
Address string
Dim x As Variant
If RefCell Is Nothing Then Set RefCell = ActiveCell
If R1C1_output = xlR1C1 Then
x = Application.ConvertFormula(Address, xlA1, xlR1C1, , RefCell)
'Convert A1 to R1C1
Else
x = Application.ConvertFormula(Address, xlR1C1, xlA1, , RefCell)
'Convert R1C1 to A1
End If
If IsError(x) Then
R1C1converter = Address
Else

'If input address is A1 reference and A1 is requested output, then
Application.ConvertFormula
'surrounds the address in single quotes.
If Right(x, 1) = "'" Then
R1C1converter = Mid(x, 2, Len(x) - 2)
Else
R1C1converter = x
End If
End If
End Function