SCRAMBLE

SCRAMBLE(sCellContents)
Returns the characters of a text string with all the characters in a random order.

sCellContentsThe number or text you want to scramble.

REMARKS
You can use the RANDOMNUMBER function to return a random number between two bounds.

 A
1=JS.SCRAMBLE("sometext")
2=JS.SCRAMBLE("better solutions")
3=JS.SCRAMBLE("better solutions")
4=JS.SCRAMBLE("123456")
5=JS.SCRAMBLE("123456")

1 - What is the text string "some text" with all the characters in a random order.
2 - What is the text string "better solutions" with all the characters in a random order.


Public Function SCRAMBLE( _ 
         ByVal sCellContents As String) _
         As String

Dim itextlength As Integer
Dim ichar As Integer
Dim irandomposition As Integer
Dim scharacter As String * 1

   itextlength = Len(sCellContents)
   For ichar = 1 To itextlength
       scharacter = VBA.Mid(sCellContents, ichar, 1)
       irandomposition = VBA.Int((itextlength - 1 + 1) * VBA.Rnd + 1)
       Mid(sCellContents, ichar, 1) = VBA.Mid(sCellContents, irandomposition, 1)
       Mid(sCellContents, irandomposition, 1) = scharacter
   Next ichar
   
   SCRAMBLE = sCellContents
End Function


© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext