Randomly Rearrange Letters in a Word to Provide a List of 100 Rearrangements

rwmill9716

Active Member
Joined
May 20, 2006
Messages
493
Office Version
  1. 2013
Platform
  1. Windows
I need a macro that will take a word that I supply in Cell A1 then randomly rearrange its letters 100 times supplying those rearrangements in Cells B1 to B100. Note, the initial word can vary in length, and every letter needs to be used without replacement. As an example, when I put heritage in A1, it might come back with gtaerieh in B1 and others in B2 to B100.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try this:

VBA Code:
Sub RandomWord()
  Dim n As Long, i As Long, j As Long, k As Long, x As Long, y As Long
  Dim arr As Variant
  Dim vle As String, cad As String
  
  vle = Range("A1").Value
  n = Len(vle)
  arr = Evaluate("=ROW(1:" & n & ")")
  
  For j = 1 To 100
    For i = 1 To UBound(arr)
      x = Int(UBound(arr) * Rnd + 1)
      y = arr(x, 1)
      arr(x, 1) = arr(i, 1)
      arr(i, 1) = y
    Next
    cad = ""
    For k = 1 To UBound(arr)
      cad = cad & Mid(vle, arr(k, 1), 1)
    Next
    Range("B" & j).Value = cad
  Next
End Sub
 
Upvote 0
Try this:

VBA Code:
Sub RandomWord()
  Dim n As Long, i As Long, j As Long, k As Long, x As Long, y As Long
  Dim arr As Variant
  Dim vle As String, cad As String
 
  vle = Range("A1").Value
  n = Len(vle)
  arr = Evaluate("=ROW(1:" & n & ")")
 
  For j = 1 To 100
    For i = 1 To UBound(arr)
      x = Int(UBound(arr) * Rnd + 1)
      y = arr(x, 1)
      arr(x, 1) = arr(i, 1)
      arr(i, 1) = y
    Next
    cad = ""
    For k = 1 To UBound(arr)
      cad = cad & Mid(vle, arr(k, 1), 1)
    Next
    Range("B" & j).Value = cad
  Next
End Sub
DanteAmor, your macro works great. One more question: is there a formula (or macro) that I could use in Col C that would identify as to whether its Colm B member is an English word or just gibberish? I
 
Upvote 0
I need a macro that will take a word that I supply in Cell A1 then randomly rearrange its letters 100 times supplying those rearrangements in Cells B1 to B100. Note, the initial word can vary in length, and every letter needs to be used without replacement. As an example, when I put heritage in A1, it might come back with gtaerieh in B1 and others in B2 to B100.
In 365 can be done with a formula

Cell Formulas
RangeFormula
B1:B10B1=LET(l,LEN(A$1),r,RANDARRAY(l),s,MATCH(SMALL(r,SEQUENCE(l)),r,0), TEXTJOIN("",1,MID(A$1,s,1)))
 
Upvote 0
is there a formula (or macro) that I could use in Col C that would identify as to whether its Colm B member is an English word or just gibberish?
Try this:

VBA Code:
Sub RandomWord()
  Dim n As Long, i As Long, j As Long, k As Long, x As Long, y As Long
  Dim arr As Variant, b As Variant
  Dim vle As String, cad As String
  Dim boo As Boolean
  
  vle = Range("A1").Value
  n = Len(vle)
  arr = Evaluate("=ROW(1:" & n & ")")
  ReDim b(1 To 100, 1 To 2)
  
  For j = 1 To 100
    For i = 1 To UBound(arr)
      x = Int(UBound(arr) * Rnd + 1)
      y = arr(x, 1)
      arr(x, 1) = arr(i, 1)
      arr(i, 1) = y
    Next
    cad = ""
    For k = 1 To UBound(arr)
      cad = cad & Mid(vle, arr(k, 1), 1)
    Next
    b(j, 1) = cad
    If Application.CheckSpelling(cad) Then
      b(j, 2) = "English word"
    Else
      b(j, 2) = "Gibberish"
    End If
  Next

  Range("B1").Resize(UBound(b, 1), 2).Value = b
End Sub
 
Upvote 0
Solution
Your program encountered a problem as shown in yellow.
 

Attachments

  • 211223 Random Word.jpg
    211223 Random Word.jpg
    50 KB · Views: 8
Upvote 0
Try this:

VBA Code:
Sub RandomWord()
  Dim n As Long, i As Long, j As Long, k As Long, x As Long, y As Long
  Dim arr As Variant, b As Variant
  Dim vle As String, cad As String
  Dim boo As Boolean
 
  vle = Range("A1").Value
  n = Len(vle)
  arr = Evaluate("=ROW(1:" & n & ")")
  ReDim b(1 To 100, 1 To 2)
 
  For j = 1 To 100
    For i = 1 To UBound(arr)
      x = Int(UBound(arr) * Rnd + 1)
      y = arr(x, 1)
      arr(x, 1) = arr(i, 1)
      arr(i, 1) = y
    Next
    cad = ""
    For k = 1 To UBound(arr)
      cad = cad & Mid(vle, arr(k, 1), 1)
    Next
    b(j, 1) = cad
    If Application.CheckSpelling(cad) Then
      b(j, 2) = "English word"
    Else
      b(j, 2) = "Gibberish"
    End If
  Next

  Range("B1").Resize(UBound(b, 1), 2).Value = b
End Sub
Thanks, Dante Amor, this works well.
 
Last edited by a moderator:
Upvote 0
Im glad to help you, thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,524
Messages
6,120,049
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top