String with text and numbers to ROMAN

fcohen

New Member
Joined
Jan 17, 2014
Messages
32
Hi,

I need a formula to replace numbers within a strin to Roman:

My18Example22Is

would become

MyXVIIIExampleXXIIIs
 

Some videos you may like

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,616
Try this UDF:

Code:
Public Function CvtRoman(text As String) As String

    Dim re As Object
    Dim matches As Object
    Dim i As Long, p As Long
    
    Set re = CreateObject("VBScript.RegExp")
    With re
        .Pattern = "\d+"
        .Global = True
        Set matches = .Execute(text)
    End With
    
    CvtRoman = ""
    p = 0
    For i = 0 To matches.Count - 1
        CvtRoman = CvtRoman & Mid(text, p + 1, matches(i).FirstIndex - p) & Application.WorksheetFunction.Roman(matches(i).Value)
        p = matches(i).FirstIndex + matches(i).Length
    Next
    If p < Len(text) Then CvtRoman = CvtRoman & Mid(text, p + 1)
    
End Function
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,686
Office Version
  1. 2010
Platform
  1. Windows
Here is another UDF you can try...
Code:
[table="width: 500"]
[tr]
	[td]Function Romanize(S As String) As String
  Dim X As Long, Num As String
  Romanize = "X" & S
  For X = Len(Romanize) To 2 Step -1
    If Mid(Romanize, X - 1, 2) Like "[!0-9]#" Then
      Num = Val(Mid(Romanize, X))
      Romanize = Application.Replace(Romanize, X, Len(Num), Application.Roman(Num))
    End If
  Next
  Romanize = Mid(Romanize, 2)
End Function[/td]
[/tr]
[/table]
 

Watch MrExcel Video

Forum statistics

Threads
1,122,628
Messages
5,597,241
Members
414,133
Latest member
lucid33

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top