Skip i'r prif gynnwys

Sut i gynhyrchu neu restru'r holl drawsnewidiadau posibl yn Excel?

Er enghraifft, mae gen i dri chymeriad XYZ, nawr, rydw i eisiau rhestru'r holl drawsnewidiadau posib yn seiliedig ar y tri chymeriad hyn i gael chwe chanlyniad gwahanol fel hyn: XYZ, XZY, YXZ, YZX, ZXY a ZYX. Yn Excel, sut allech chi gynhyrchu neu restru'r holl drawsnewidiadau yn gyflym yn seiliedig ar nifer wahanol o gymeriadau?

Cynhyrchu neu restru'r holl drawsnewidiadau posibl yn seiliedig ar gymeriadau â chod VBA


swigen dde glas saeth Cynhyrchu neu restru'r holl drawsnewidiadau posibl yn seiliedig ar gymeriadau â chod VBA

Efallai y bydd y cod VBA canlynol yn eich helpu i restru'r holl drawsnewidiadau yn seiliedig ar eich nifer benodol o lythyrau, gwnewch fel a ganlyn:

1. Daliwch i lawr y ALT + F11 allweddi i agor y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

2. Cliciwch Mewnosod > Modiwlau, a gludwch y cod canlynol yn y Modiwlau Ffenestr.

Cod VBA: Rhestrwch yr holl drawsnewidiadau posib yn excel

Sub GetString()
'Updateby Extendoffice
    Dim xStr As String
    Dim FRow As Long
    Dim xScreen As Boolean
    xScreen = Application.ScreenUpdating
    Application.ScreenUpdating = False
    xStr = Application.InputBox("Enter text to permute:", "Kutools for Excel", , , , , , 2)
    If Len(xStr) < 2 Then Exit Sub
    If Len(xStr) >= 8 Then
        MsgBox "Too many permutations!", vbInformation, "Kutools for Excel"
        Exit Sub
    Else
        ActiveSheet.Columns(1).Clear
        FRow = 1
        Call GetPermutation("", xStr, FRow)
    End If
    Application.ScreenUpdating = xScreen
End Sub
Sub GetPermutation(Str1 As String, Str2 As String, ByRef xRow As Long)
    Dim i As Integer, xLen As Integer
    xLen = Len(Str2)
    If xLen < 2 Then
        Range("A" & xRow) = Str1 & Str2
        xRow = xRow + 1
    Else
        For i = 1 To xLen
            Call GetPermutation(Str1 + Mid(Str2, i, 1), Left(Str2, i - 1) + Right(Str2, xLen - i), xRow)
        Next
    End If
End Sub

3. Yna pwyswch F5 allwedd i redeg y cod hwn, ac mae blwch prydlon yn cael ei popio allan i'ch atgoffa i nodi'r cymeriadau rydych chi am restru'r holl drawsnewidiadau, gweler y screenshot:

permutations rhestr doc 1

4. Ar ôl mynd i mewn i'r cymeriadau, ac yna cliciwch OK botwm, mae'r holl drawsnewidiadau posib yn cael eu harddangos yng ngholofn A y daflen waith weithredol. Gweler y screenshot:

permutations rhestr doc 2

Nodyn: Os yw hyd y cymeriad a gofnodwyd yn hafal neu'n fwy nag 8 nod, ni fydd y cod hwn yn gweithio oherwydd bod gormod o drawsnewidiadau.

permutations rhestr doc 3


Rhestrwch neu gynhyrchwch yr holl gyfuniadau posib o sawl colofn

Os oes angen i chi gynhyrchu'r holl gyfuniadau posibl yn seiliedig ar ddata colofnau lluosog, efallai, nid oes ffordd dda o ddelio â'r dasg. Ond, Kutools ar gyfer Excel's Rhestrwch Pob Cyfuniad gall cyfleustodau eich helpu i restru'r holl gyfuniadau posibl yn gyflym ac yn hawdd. Cliciwch i lawrlwytho Kutools ar gyfer Excel!

mae doc yn rhestru pob cyfuniad

Kutools ar gyfer Excel: gyda mwy na 300 o ychwanegiadau Excel defnyddiol, am ddim i geisio heb unrhyw gyfyngiad mewn 30 diwrnod. Dadlwythwch a threial am ddim Nawr!

Offer Cynhyrchiant Swyddfa Gorau

🤖 Kutools AI Aide: Chwyldro dadansoddi data yn seiliedig ar: Cyflawniad Deallus   |  Cynhyrchu Cod  |  Creu Fformiwlâu Personol  |  Dadansoddi Data a Chynhyrchu Siartiau  |  Invoke Swyddogaethau Kutools...
Nodweddion Poblogaidd: Darganfod, Amlygu neu Adnabod Dyblygiadau   |  Dileu Rhesi Gwag   |  Cyfuno Colofnau neu Gelloedd heb Colli Data   |   Rownd heb Fformiwla ...
Super-edrych: VLookup Meini Prawf Lluosog    VLookup Gwerth Lluosog  |   VLookup Ar Draws Taflenni Lluosog   |   Edrych Niwlog ....
Rhestr gwympo Uwch: Creu Rhestr Gollwng yn Gyflym   |  Rhestr Gollwng Dibynnol   |  Rhestr Gollwng Aml-ddewis ....
Rheolwr Colofn: Ychwanegu Nifer Penodol o Golofnau  |  Symud Colofnau  |  Toglo Statws Gwelededd Colofnau Cudd  |  Cymharwch Ystodau a Cholofnau ...
Nodweddion dan Sylw: Ffocws ar y Grid   |  Golwg Dylunio   |   Bar Fformiwla Mawr    Rheolwr Llyfr Gwaith a Thaflen   |  Llyfrgell Adnoddau (Testun Auto)   |  Dewiswr Dyddiad   |  Cyfuno Taflenni Gwaith   |  Amgryptio/Dadgryptio Celloedd    Anfon E-byst trwy Restr   |  Hidlo Super   |   Hidlo Arbennig (hidlo mewn print trwm/italig/strikethrough...) ...
15 Set Offer Gorau12 Testun offer (Ychwanegu Testun, Dileu Cymeriadau,...)   |   50 + Siart Mathau (Siart Gantt,...)   |   40+ Ymarferol Fformiwlâu (Cyfrifwch oedran yn seiliedig ar ben-blwydd,...)   |   19 mewnosod offer (Mewnosod Cod QR, Mewnosod Llun o'r Llwybr,...)   |   12 Trosi offer (Rhifau i Eiriau, Trosi arian cyfred,...)   |   7 Uno a Hollti offer (Rhesi Cyfuno Uwch, Celloedd Hollt,...)   |   ... a mwy

Supercharge Eich Sgiliau Excel gyda Kutools ar gyfer Excel, a Phrofiad Effeithlonrwydd Fel Erioed Erioed. Kutools ar gyfer Excel Yn Cynnig Dros 300 o Nodweddion Uwch i Hybu Cynhyrchiant ac Arbed Amser.  Cliciwch Yma i Gael Y Nodwedd Sydd Ei Angen Y Mwyaf...

Disgrifiad


Mae Office Tab yn dod â rhyngwyneb Tabbed i Office, ac yn Gwneud Eich Gwaith yn Haws o lawer

  • Galluogi golygu a darllen tabbed yn Word, Excel, PowerPoint, Cyhoeddwr, Mynediad, Visio a Phrosiect.
  • Agor a chreu dogfennau lluosog mewn tabiau newydd o'r un ffenestr, yn hytrach nag mewn ffenestri newydd.
  • Yn cynyddu eich cynhyrchiant 50%, ac yn lleihau cannoedd o gliciau llygoden i chi bob dydd!
Comments (13)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Olá !

Como faço para gerar pelo menos 10 permutações ?
This comment was minimized by the moderator on the site
Hello, Mateus,
To solve your problem, please apply the below code:(Note: if there are more than 8 characters, the code will execute slowly.)
Sub GetString()
'Updateby Extendoffice
    Dim xStr As String
    Dim FRow As Long
    Dim FC As Integer
    Dim xScreen As Boolean
    Dim xNumber As Long
    xNumber = 10 ' This is the max length of the characters you can change it to 11, 12, 13...as you need
    xScreen = Application.ScreenUpdating
    Application.ScreenUpdating = False
    xStr = Application.InputBox("Enter text to permute:", "Kutools for Excel", , , , , , 2)
    If Len(xStr) < 2 Then Exit Sub
    If Len(xStr) > xNumber Then
        MsgBox "Too many permutations!", vbInformation, "Kutools for Excel"
        Exit Sub
    Else
        ActiveSheet.Columns(1).Clear
        FRow = 1
        FC = 1
        Call GetPermutation("", xStr, FRow, FC)
    End If
    Application.ScreenUpdating = xScreen
End Sub
Sub GetPermutation(Str1 As String, Str2 As String, ByRef xRow As Long, ByRef xc As Integer)
    Dim i As Integer, xLen As Integer
    xLen = Len(Str2)
    If xLen < 2 Then
        If xRow > 1000000 Then
            xc = xc + 1
            xRow = 1
        End If
       ActiveSheet.Cells(xRow, xc) = Str1 & Str2
        xRow = xRow + 1
    Else
        For i = 1 To xLen
            Call GetPermutation(Str1 + Mid(Str2, i, 1), Left(Str2, i - 1) + Right(Str2, xLen - i), xRow, xc)
        Next
    End If
End Sub


Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
Hi there, if the input string contains duplicate chars, then the sub produces duplicate permutations.
This does not happen if you make the following modification the the loop:

' ==========================
For i = 1 To xLen
If Instr( Left(Str2, i - 1), Mid(Str2, i, 1) ) = 0 then
Call GetPermutation(Str1 + Mid(Str2, i, 1), Left(Str2, i - 1) + Right(Str2, xLen - i), xRow)
End if
Next
' ==========================

Creating temporary local variables for Mid(Str2, i, 1) and for Left(Str2, i - 1), and avoiding the test for i=1 makes it go faster:


' ==========================
Sub GetPermutation(Str1 As String, Str2 As String, ByRef xRow As Long)
Dim i As Integer, xLen As Integer, Str2left as String, c as String
xLen = Len(Str2)
If xLen < 2 Then
Range("A" & xRow) = Str1 & Str2
xRow = xRow + 1
Else
Call GetPermutation(Str1 + Mid(Str2, 1, 1), Right(Str2, xLen - 1), xRow)
For i = 2 To xLen
c = Mid(Str2, i, 1)
Str2left = Left(Str2, i - 1)
If Instr( Str2left, c ) = 0 then
Call GetPermutation(Str1 + c, Str2left + Right(Str2, xLen - i), xRow)
End If
Next
End If
End Sub
' ==========================

Cheers,
DVdm
This comment was minimized by the moderator on the site
who can send me a list of 10 diferent items permutatted by 2 outcomes. this code doe

snt work on this
This comment was minimized by the moderator on the site
peki bunu listeleyecek bir program uygulama yok mu?basit sıradan bir hesaplamadan daha fazlasına ihtiyacı olan ne yapacak?
This comment was minimized by the moderator on the site
this code will not work because there are two many permutations


should be:

this code will not work because there are too many permutations


HTH
This comment was minimized by the moderator on the site
Hello, MC,
Thank you for your warm reminder, it is my mistake. I have corrected it.
Thanks a lot!
This comment was minimized by the moderator on the site
Hello everyone. I need help on this. I have two alphabets to be permutated in 20 rows. But am not getting it right. Anyone who could help me out should send the permutation to my email. .


1.a b b a
2.a a b b
3.a a b b
4.a a b b
5.a a b b
6.a a b b
7.a a b b
8.a a b b
9.a a b b
10.a a b b
11.a a b b
12.a a b b
13.a a b b
14.a a b b
15.a a b b
16.a a b b
17.a a b b
18.a a b b
19.a a b b
20.a a b b
This comment was minimized by the moderator on the site
How many sequences of 3things can be formed from 7 different things replacement and order is important?
This comment was minimized by the moderator on the site
3 to the power of 7: 2187
This comment was minimized by the moderator on the site
@Supraja...

in the first sub clear all cells... not just the first row
--Cells.Clear

Sub GetPermutation(Str1 As String, Str2 As String, ByRef xRow As Long)
Dim i As Integer, xLen As Integer
xLen = Len(Str2)
If xLen < 2 Then
'move to the next column when you get to 100
Cells(((xRow - 1) Mod 100) + 1, 1 + Int(xRow / 100)) = Str1 & Str2
xRow = xRow + 1
Else
For i = 1 To xLen
Call GetPermutation(Str1 + Mid(Str2, i, 1), Left(Str2, i - 1) + Right(Str2, xLen - i), xRow)
Next
End If
End Sub
This comment was minimized by the moderator on the site
Hello,

Im trying to get a permutation for 82 characters, the code provided works, but, since the columns are only 1048576, I want to move the next output in B,C,D..... Can any of you help me on this regard
This comment was minimized by the moderator on the site
Hello, Im doing a small project using permutation and combination rules. I need your support on this please. Scenario: I have 13 digit alpha numeric data (00SHGO8BJIDG0) I want a coding to interchange S to 5, I to 1 and O to 0 and vise versa. The project is that if I have the correct 13 digit data I will receive a 3 digit pass code. (eg) 00SHG08BJ1DG0 - 500 is the pass code but because of wrong typo that is instead of 1 it was I and 0 it was O there is a wrong info. can you please help me.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations