View Single Post
 
Old 06-17-2015, 01:19 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

I love these seemingly pointless puzzles
You cannot do it with replace, but you can do it with a macro http://www.gmayor.com/installing_macro.htm

Code:
Option Explicit

Sub RandomLetters()
Dim oRng As Range
Dim oFind As Range
Dim i As Long
Dim strChar As String
Start:
    strChar = InputBox("Replace which character?", , "a")
    If Len(strChar) > 1 Or Not IsLetter(asc(strChar)) Then
        MsgBox "Enter a single character from the ranges A-Z or a-z only", vbCritical
        GoTo Start
    End If
    Set oFind = Selection.Range
    Set oRng = Selection.Range
    For i = 1 To oRng.Characters.Count
        With oRng.Find
            Do While .Execute(FindText:=strChar, MatchCase:=True)
                If oRng.InRange(oFind) Then
                    oRng.Text = RandomLetter(strChar)
                    oRng.Font.ColorIndex = wdRed
                End If
                oRng.Collapse wdCollapseEnd
            Loop
        End With
    Next i
End Sub

Private Function IsLetter(ByVal i As Integer) As Boolean
Select Case i
        Case 65 To 90, 97 To 122
            IsLetter = True
        Case Else
            IsLetter = False
    End Select
lbl_Exit:
    Exit Function
End Function

Private Function RandomLetter(strChar As String) As String
    Select Case asc(strChar)
        Case 65 To 90
            RandomLetter = Chr(65 + Rnd() * 10000000 Mod 26)
        Case 97 To 122
            RandomLetter = Chr(97 + Rnd() * 10000000 Mod 26)
        Case Else
            RandomLetter = strChar
    End Select
lbl_Exit:
    Exit Function
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote