View Single Post
 
Old 01-12-2024, 12:30 AM
vivka vivka is offline Windows 7 64bit Office 2016
Expert
 
Join Date: Jul 2023
Posts: 302
vivka is on a distinguished road
Default

Hi! Here is a simple option. I used some ideas from a Guessed's code (https://www.msofficeforums.com/179302-post6.html). You can modifiy the code to meet your needs. Maybe someone can suggest something more elegant.
Code:
Sub Repl_Digits_If()
'In the selected range, replace all single digits that start
'specifically indented paragraphs with asterisks.

Dim oRng As range
Dim oPar As Paragraph
Dim arrText() As String
Dim oDgt As range

Application.ScreenUpdating = False
Set oRng = selection.range
arrText = Split("zero one two three four five six seven eight nine", " ")

    For Each oPar In oRng.Paragraphs
        If oPar.range.ParagraphFormat.FirstLineIndent >= 0.5 And _
            oPar.range.Characters(1) Like "[0-9]*" And _
            oPar.range.Characters(2) Like "[!0-9]*" Then
                Set oDgt = oPar.range.Characters(1)
                oDgt.text = arrText(oDgt.text)
                oDgt.Font.ColorIndex = wdBrightGreen
        End If
    Next oPar
Application.ScreenUpdating = True
Set oRng = Nothing
End Sub
Reply With Quote