Try this UDF:
Option Base 1
Function arab(romai As String, Optional forma)
rbetuk = Array("I", "V", "X", "L", "C", "D", "M")
ertekek = Array(1, 5, 10, 50, 100, 500, 1000)
sulyok = Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
elojelek = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
hossz = Len(romai)
For i = 1 To hossz
sulyok(i) = ertekek(WorksheetFunction.Match(Mid(romai, i, 1),
rbetuk, 0))
If i < hossz Then
If sulyok(i) < ertekek(WorksheetFunction.Match(Mid(romai, i + 1,
1), rbetuk, 0)) Then
elojelek(i) = -1 'előjel
End If
End If
Next i
arab = WorksheetFunction.SumProduct(sulyok, elojelek)
If IsMissing(forma) Then
If Not (romai = WorksheetFunction.Roman(arab, 0) Or _
romai = WorksheetFunction.Roman(arab, 1) Or _
romai = WorksheetFunction.Roman(arab, 2) Or _
romai = WorksheetFunction.Roman(arab, 3) Or _
romai = WorksheetFunction.Roman(arab, 4)) _
Then arab = WorksheetFunction.Match("A", rbetuk, 0)
Else
If Not (romai = WorksheetFunction.Roman(arab, forma)) _
Then arab = WorksheetFunction.Match("A", rbetuk, 0)
End If
End Function
Usage:
If you omit "forma" argument, then the function converts Roman numbers of
any type (See Help on function ROMAN), if you supply "forma" argument, the
function converts only Roman numbers of the given type.
Regards,
Stefi
„IanW†ezt Ãrta: