Page 1 of 1

Permutation

Posted: Sat Jul 30, 2022 5:41 pm
by sna
Hi Dear,


I have written a macro to create permutations .with combination of letters a,b,c...

Code: Select all


Sub Permutation (num As Long)

Dim str As String

Application.ScreenUpdating = False

If num >= 1 Then

    For a = 97 To 122

        If num >= 2 Then

            For b = 197 To 122

                If num >= 3 Then

                    For c = 97 To 122

                        str = chr(a) & chr(b)& chr(c)

                        If Range("a1").Value = "" Then

                            Range("a1").Value = str

                        Else

                            Range("a" & Rows.Count).End(xlUp).Offset(1, 0).Value = str

                        End If

                    Next

                Else

                    str = chr(a) & chr(b)

                    If Range("a1").Value = "" Then

                        Range("a1").Value = str

                    Else

                        Range("a" & Rows.Count).End(xlUp).Offset(1, 0).Value = str

                    End If

                End If

            Next

        Else

            str =chr(a)

            If Range("a1").Value = "" Then

                Range("a1").Value = str

            Else

                Range("a" & Rows.Count).End(xlUp).Offset(1, 0).Value = str

            End If

        End If

    Next

End If

End Sub
should I place it in a module like Call Permutation (5) ,right?

Thanks

Re: Permutation

Posted: Sun Jul 31, 2022 6:38 pm
by snasui
:D Yes, you can call this procedure with other procedure by specify number as argument.

Re: Permutation

Posted: Sun Jul 31, 2022 8:01 pm
by sna
thank you 😊

Re: Permutation

Posted: Thu Aug 04, 2022 12:47 pm
by sna
I had given this to a friend
Sub MyMacro()
Call Permutation (4)
End Sub
He said it was not working fine

Thanks

Re: Permutation

Posted: Sat Aug 06, 2022 7:01 pm
by snasui
:D I don't think so. Please tell him to ask his problem in this place by himself.

Re: Permutation

Posted: Mon Aug 08, 2022 9:47 pm
by sna
Ok thanks 😊