Formula Forensics No. 041 – Convert a Roman Numeral to a Number

Posted on September 14th, 2016 in Excel Howtos , Formula Forensics , Huis , Posts by Hui - 6 comments

Last week in the Forums a user asked a question

How do I convert a Roman Numeral to a Number eg: MMMCCCLVII to 3357

User Xlstime presented the solution of:


Today we are going to look at how and why that simple formula works

As always at Formula Forensics you can follow along using a sample file: Download Sample File


Excel has a Roman function wherein =Roman(3357, 0) will return MMMCCCLVII

I knew there was no such reverse Roman function prior to Excel 2013 and so my initial thought was to look at a VBA Solution.

See notes on the Arabic Excel function at the end of the post.

However Xlstime presented =MATCH(A2,INDEX(ROMAN(ROW(INDIRECT(“1:3999”))),0),0)

How does this work?

lets start by pulling it apart from the inside out


The Indirect Function simply takes its inputs and converts them to a Range, in this case 1:3999.

We will study why 3999 later


The next function working out is Row()

Excel will convert the function ROW(INDIRECT(“1:3999”)) to an array of Row Numbers

={1;2;3;4;5;6;7;8;9;10;11; …. 3995;3996;3997;3998;3999}

You can see this if you goto cell D7 in the Sample File, press F2 and then F9

I limited the numbers to 300 as Excel cannot display more than 8,192 digits

Stepping out one more function:


The Roman() function converts its inputs into Roman Numbers

eg: Roman(58) will return LVIII

But as we are feeding it an array of numbers from 1 to 3999 Excel handles all these and converts them to an Array of Roman Numbers

Goto  D9 in the sample file =ROMAN(ROW(INDIRECT(“1:300”))) press F2 and then F9

Excel returns an array of roman numbers


We have limited the example to 300 as Excel cannot display more than 8,192 characters when processing  a Function using F9.


Stepping out one more function


The Excel Index() function is taking the Array of Roman Numerals and Converting it into a single Column array

This isn’t technically needed but it simplifies the solution

If you goto cell D11 in the sample file =INDEX(ROMAN(ROW(INDIRECT(“1:3999”))),0) press F2 and then F9

Excel returns an array of roman numbers


This is exactly the same as the previous output from the Roman() function above, Except that it is now a Single Vertical Array.  This is important for the next function.


Stepping out one more function


We can see here that the Array of Roman Numerals is now being fed into a Match() function.

Match uses the Syntax =Match(Lookup value, Lookup Array, Match Type)

Match returns the position of the Lookup value within the array

So in our example

The Lookup value is A2 or our Roman Numeral MMMCCCLVII

The Lookup Array is an array of Roman Numerals from 1 to 3999


and the Match Type is 0 or an exact Match

So the Match function will lookup the value MMMCCCLVII in the array and find it in position number 3357, which happens to correspond to the Number of the Roman Numeral and Return 3357 as the result.

Why are we limited to 3999 numbers.

The Excel Roman() function is limited to numbers up to 3999


Why 3999?

Because in Roman Numerals there is no Letter for 5,000 and 4,000 would be shown as M before the Letter for 5,000.


Why did we need the Index() function?

If you goto D17 in the sample file you will see the formula:


It is the same formula as above but without the Index() function

You will see that it is returning a #VALUE! error

If you edit the formula with F2 and then press F9 to process the function you will see it now shows 3357

What s happening here?

Pressing F9 is the same as Array Entering the Function

so if you edit the function pressing F2 and now Array Enter the function by pressing Ctrl+Shift+Enter, excel now returns 3357

The Index() function puts a wrapper around the array for processing by the Match() function and so Array Entering is avoided.

Most array formulas that require Ctrl+Shift+Enter can be rewritten incorporating an INDEX wrapper and will not require the Ctrl+Shift+Enter confirmation.

The Excel Arabic Function

In 2013, Microsoft introduced the Arabic function to Excel

To use simply use =Arabic(A2) or =Arabic(“MMMCCCLVII”)

You can read about the Syntax of the function in the Excel Help.



You can download a copy of the above file and follow along, Download Sample File.


A Challenge

Can you solve the problem another way ?

Post your solutions in the comments below.


Other Posts in this Series

The Formula Forensics Series contains a wealth of useful solutions and information specifically about how Normal Formula and specifically Array Formula work.

You can learn more about how to pull Excel Formulas apart in the following posts:

If you have a formula and you want to understand how it works contact Hui and it may be featured in future posts.


Written by Hui...
Tags: , , , , ,
Home: Main Page
? Doubt: Ask an Excel Question

6 Responses to “Formula Forensics No. 041 – Convert a Roman Numeral to a Number”

  1. PINOY-exceler says:

    shortened it a bit but same principle


  2. XLSTIME says:

    Thank you Chandoo for publishing this.

  3. Herbert says:

    Hi Chandoo,
    Great post.
    Question: why would you include the INDIRECT function in the formula? I tried =MATCH(A2,INDEX(ROMAN(ROW(1:3999)),0),0) and this gives the same result.


  4. Lori says:

    The formula from the post is remarkably similar to one i posted back in 2007:
    Interestingly, it actually seems to run slightly faster and use less memory with the additional INDEX() function inserted since the array formulas have a small overhead associated so i agree with Hui that it is probably a good idea imo remove CSE.

    Another possibility which is longer but significantly more efficient:
    Credit is due to Harlan Grove from which it was adapted.

    As chandoo says, the ARABIC function is definitely the way to go in 2013 version and above.

Leave a Reply