Results 1 to 27 of 27

Improve number combination vba

Threaded View

  1. #1
    Registered User
    Join Date
    01-06-2013
    Location
    New York, EUA
    MS-Off Ver
    Excel 2013
    Posts
    77

    Improve number combination vba

    Hello, Friends,

    The following vba is used to combine "n" numbers (written in column A), picked "p" by "p" (written in cell "B1").

    Public NumRows As Long
    Public NumCols As Long
    Public j As Long
    Public ColStep As Long
    Public StartCol As Long
    
    Sub Combinations()
    
    Dim rRng As Range, p As Integer
    Dim vElements, lRow As Long, vresult As Variant
    
    StartCol = 3   'Starts in Column "C"
    ColStep = 14  'Column Step
    j = StartCol
    NumRows = ActiveSheet.Rows.Count
    NumCols = ActiveSheet.Columns.Count
    
    Set rRng = Range("A1", Range("A1").End(xlDown)) ' The set of numbers
    p = Range("B1").Value ' How many are picked
    
    vElements = Application.Index(Application.Transpose(rRng), 1, 0)
    ReDim vresult(1 To p)
    Call CombinationsNP(vElements, p, vresult, 1, 1)
    End Sub
    Sub CombinationsNP(vElements As Variant, p As Integer, vresult As Variant, iElement As Integer, iIndex As Integer)
    Dim i As Integer
    
    For i = iElement To UBound(vElements)
    vresult(iIndex) = vElements(i)
    If iIndex = p Then
    Cells(Application.Rows.Count, j).End(xlUp).Offset(1, 0).Resize(, p) = vresult
    Cells(Application.Rows.Count, j).End(xlUp).Select
    
       If (ActiveCell.Address = Cells(NumRows - 1, j).Address) Then
          j = j + ColStep
          If ((j + p) > NumCols) Then
             Sheets.Add After:=Sheets(ActiveSheet.Name)
             j = StartCol
          End If
          Cells(1, j).Select
       Else
    
          Cells(Application.Rows.Count, j).End(xlUp).Select
       End If
    
    Else
    Call CombinationsNP(vElements, p, vresult, i + 1, iIndex + 1)
    Cells(Application.Rows.Count, j).End(xlUp).Select
    
    End If
    
    Next i
    End Sub
    The Windows Task Manager shows that the memory usage is only 260MB !!!!

    So, I would like to ask your help to improve this code in order to INCREASE THE MEMORY USAGE.

    Thanks,

    John
    Last edited by JOAO12; 07-28-2018 at 10:15 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need help for creating a combination of number
    By factorjones in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-20-2017, 07:23 AM
  2. Combination without repetitions from 5 sets of number
    By alboholic in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-19-2016, 12:11 PM
  3. Text/number combination that I want to add
    By kjurss in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-03-2016, 10:21 AM
  4. Assign number to combination of checkboxes
    By laguna92651 in forum Excel General
    Replies: 3
    Last Post: 11-11-2014, 01:20 AM
  5. 6 Number Combination
    By shart2k12 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-13-2013, 07:20 PM
  6. Excel 2007 : different number combination
    By dh1 in forum Excel General
    Replies: 1
    Last Post: 04-21-2010, 12:11 AM
  7. number combination searching
    By labman in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 09-06-2007, 02:24 AM

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