Results 1 to 4 of 4

Defined numbers - generator.

Threaded View

LOxEN Defined numbers - generator. 11-01-2012, 08:45 AM
Special-K Re: Defined numbers -... 11-01-2012, 12:03 PM
LOxEN Re: Defined numbers -... 11-02-2012, 08:37 AM
Jakobshavn Re: Defined numbers -... 11-02-2012, 10:16 AM
  1. #4
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Defined numbers - generator.

    There are 840 unique permutations of the 7 values. This small macro, TEST, will list them in column A:

    Sub TEST()
    Dim j As Long, k As Long
    k = 1
    Application.ScreenUpdating = False
    For j = 1333459 To 9543331
        If NumCheck(CStr(j)) Then
            Cells(k, 1) = j
            k = k + 1
            ' If k = 1000 Then Exit Sub
        End If
    Next
    Application.ScreenUpdating = True
    End Sub
    Function NumCheck(s As String) As Boolean
    NumCheck = False
    If InStr(s, "0") + InStr(s, "2") + InStr(s, "6") + InStr(s, "7") + InStr(s, "8") = 0 Then
        If Len(Replace(s, "1", "")) = 6 And Len(Replace(s, "4", "")) = 6 And Len(Replace(s, "9", "")) = 6 Then
            If Len(Replace(s, "3", "")) = 4 Then
                NumCheck = True
                Exit Function
            End If
        End If
    End If
    End Function
    Macros are very easy to install and use:

    1. ALT-F11 brings up the VBE window
    2. ALT-I
    ALT-M opens a fresh module
    3. paste the stuff in and close the VBE window

    If you save the workbook, the macro will be saved with it.

    To remove the macro:

    1. bring up the VBE window as above
    2. clear the code out
    3. close the VBE window

    To use the macro from Excel:

    1. ALT-F8
    2. Select the macro (TEST)
    3. Touch RUN

    To learn more about macros in general, see:

    http://www.mvps.org/dmcritchie/excel/getstarted.htm

    Macros must be enabled for this to work!
    Last edited by Jakobshavn; 11-02-2012 at 10:28 AM. Reason: REMOVED BUG
    Gary's Student

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1