Microsoft Office Tutorials and References
In Depth Information
Function REVERSETEXT(text As String) As String
‘ Returns its argument, reversed
REVERSETEXT = StrReverse(text)
End Function
This function simply uses the VBA StrReverse function. The following formula, for example, returns tfosor-
Scrambling text
The following function returns the contents of its argument with the characters randomized. For example, using
Microsoft as the argument may return oficMorts, or some other random permutation.
Function SCRAMBLE(text As Variant) As String
Scrambles its string argument
Dim TextLen As Long
Dim i As Long
Dim RandPos As Long
Dim Temp As String
Dim Char As String * 1
If TypeName(text) = “Range” Then
Temp = text.Range(“A1”).text
ElseIf IsArray(text) Then
Temp = text(LBound(text))
Temp = text
End If
TextLen = Len(Temp)
For i = 1 To TextLen
Char = Mid(Temp, i, 1)
RandPos = WorksheetFunction.RandBetween(1, TextLen)
Mid(Temp, i, 1) = Mid(Temp, RandPos, 1)
Mid(Temp, RandPos, 1) = Char
Next i
End Function
This function loops through each character and then swaps it with another character in a randomly selected pos-
You may be wondering about the use of Mid. Note that when Mid is used on the right side of an assignment
statement, it is a function. However, when Mid is used on the left side of the assignment statement, it is a state-
ment. Consult the Help system for more information about Mid.
Search JabSto ::

Custom Search