Leading the way in Microsoft Office Development
 Home|Excel|Word|PowerPoint|Consultancy|Feedback|Contact 
 Microsoft Excel > Functions User Defined > SCRAMBLE< Previous | Next > 

 

SCRAMBLE(sCellContents) As String

 
 

Returns the cell contents with all the characters in a random order.

 

 
sCellContentsThe number or text you want to scramble.
 

 

REMARKS

 
 
  • Thanks to John Wakenbach for this original function.

     

     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    Option Explicit

    Public Function SCRAMBLE(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
       

     

    Example

     
       

     Copyright © 2004-2007 Better Solutions Limited. All Rights Reserved.< Previous | Top | Next >