When I put a word such as "help" or "shirt" into cell B1, I would like a macro to put all combinations of those letters into column A.
Example:
The word "help" has four letters and all results would also have four letters:
help
hple
hpel
ehlp
ehpl
elhp
elph etc.
Copyright © 2024 1QUIZZ.COM - All rights reserved.
Answers & Comments
Verified answer
mmmmmm donuts!
Ok, now that I got that out of my system.. Try this. It'll open an input box to enter the word to permute. It will list the combinations (permutations) down column A.
Dim CurrentRow
Sub GetString()
Dim InString As String
InString = InputBox("Enter text to permute:")
If Len(InString) < 2 Then Exit Sub
If Len(InString) >= 8 Then
MsgBox "Too many permutations!"
Exit Sub
Else
ActiveSheet.Columns(1).Clear
CurrentRow = 1
Call GetPermutation("", InString)
End If
End Sub
Sub GetPermutation(x As String, y As String)
Dim i As Integer, j As Integer
j = Len(y)
If j < 2 Then
Cells(CurrentRow, 1) = x & y
CurrentRow = CurrentRow + 1
Else
For i = 1 To j
Call GetPermutation(x + Mid(y, i, 1), _
Left(y, i - 1) + Right(y, j - i))
Next
End If
End Sub
This was written for 2003 and earlier, and due to the limit on rows, this limits permuations to 7 characters. In 2007 and later, you can change that to a higher number.. 9 characters will give 362880 permuations (and takes forever to run.)
Enter =COUNTA(A:A) somewhere and watch it increase with each permuation.
All Combinations Of Letters
it may were staggering if Microsoft had created a function that did something like the right, top and decrease purposes, yet became for Sentence Case. besides, right that is the Macro which could be of suggestion to you: determination specific Public Sub SentenceCase() Dim rng As decision Dim cellular As decision Set rng = ActiveWindow.RangeSelection for each cellular In rng cellular.fee = UCase( Left( cellular.fee, a million ) ) & LCase( Mid( cellular.fee, 2 )) next cellular end Sub The above will artwork for in ordinary words those cells that are chosen on the time you run the Macro. in case you pick the Macro to instantly pick all cells which have files in them around the present lively cellular, then replace the above SET actuality with right here: Set rng = ActiveCell.CurrentRegion .