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
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
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
 
Upvote 0
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]
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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
Back
Top