View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default How do I convert Roman numerals to Arabic (reverse of ROMAN)?

On Fri, 4 May 2007 03:26:02 -0700, IanW wrote:

I can use the ROMAN function, but does anyone know a way of reversing the
function to get Arabic numerals from Roman?



You can use a UDF:

==========================================
Function Arabic(rg As Range) As Long
Const m As Long = 1000
Const d As Long = 500
Const c As Long = 100
Const l As Long = 50
Const X As Long = 10
Const v As Long = 5
Const i As Long = 1

Dim temp()
Dim j As Long

ReDim temp(Len(rg.Text) - 1)

For j = 1 To Len(rg.Text)
temp(j - 1) = Mid(rg.Text, j, 1)
Next j

For j = 0 To UBound(temp)
Select Case temp(j)
Case Is = "M"
temp(j) = m
Case Is = "D"
temp(j) = d
Case Is = "C"
temp(j) = c
Case Is = "L"
temp(j) = l
Case Is = "X"
temp(j) = X
Case Is = "V"
temp(j) = v
Case Is = "I"
temp(j) = i
Case Else
MsgBox ("Illegal Character")
Exit Function
End Select
Next j

For j = 0 To UBound(temp) - 1
If temp(j) < temp(j + 1) Then
If temp(j) * 10 = temp(j + 1) And _
temp(j) = i Or _
temp(j) = X Or _
temp(j) = c Then
temp(j) = -temp(j)
Else
MsgBox ("Illegal Construction")
End If
End If
Next j

Arabic = Application.WorksheetFunction.Sum(temp)

End Function
=========================================
--ron