Results 1 to 2 of 2

Alternative to collection that will remove index at the middle, re-attach adjacent indexes

Threaded View

  1. #1
    Registered User
    Join Date
    12-20-2014
    Location
    North America
    MS-Off Ver
    2013
    Posts
    40

    Alternative to collection that will remove index at the middle, re-attach adjacent indexes

    I came up with the following algorithm, located at the end of the post, that works as intended.

    My main issue, is that when iMain goes to the next iteration, it will loop through the entire inner array/collection of unique numbers, sviColl, again. I'm planning on using this in a different implementation that will contain an index of around 45 items, and 7 unique prefixes (sheet named "sheet2 orig list"). Resulting in 315 iterations. Most of which will be very redundant.

            Do While q.Count <= allocatedRows And dwCounter1 <= sviColl.Count
    
                If sviColl(sviCollIndex).impPrefix(impPrefixColl) = impPrefixColl(iMain) Then       'Will use q.Count to space out the dequeues evenly (where applicable)
                    q.Enqueue sviColl(sviCollIndex).sourceVeh()
                End If
                
                sviCollIndex = sviCollIndex + 1
                dwCounter1 = dwCounter1 + 1
            Loop
    According to my calculations, implementing a solution similar to linked list, will reduce amount of iteration by up to 66%
    +------------+-------------+
    | Collection | Linked List |
    +------------+-------------+
    |          4 |           4 |
    |         14 |          10 |
    |         24 |          14 |
    |         32 |          18 |
    |         40 |           8 |
    |         50 |          10 |
    |         60 |          10 |
    |            |             |
    |        224 |          74 |
    +------------+-------------+
    I've come up with 2 possible solutions. Use a collection alternative similar to linked list, or send each index that doesn't match, impPrefixColl(iMain), to a new collection, destroy or clear old collection (Set Coll = Nothing), and rename new collection to that of the old collection.

    In the case of the latter solution, it seems I may have to resort to recursion, since there doesn't seem to be a way of "renaming" a collection without resorting to for loop.
    Edit: disregard the recursion

    I was thinking of using a 'Dictionary', but it seems that may leave a 'zombie index' in its place, where as a linked list will remove it completely. I've been unable to find a vba linked list that comes with an example of using it.

        For iMain = 1 To impPrefixColl.Count
            allocatedRows = 0
            
            sviCollIndex = 1
            rowToStartFilling = prefix_SearchRng.Find(What:=impPrefixColl(iMain), LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False).Row         'Perform a search range & set it to impPrefixColl(i)
            Set currentCell = myWs.Cells(rowToStartFilling, importFilePrefCell.Column)
            
        
            'Count rows allocated to present prefix
            Do While (currentCell.Value = impPrefixColl(iMain) Or currentCell.Value = "") And Not currentCell.Row > lastRowOfSheet
                Set currentCell = currentCell.Offset(1, 0)
                allocatedRows = allocatedRows + 1
            Loop
            dwCounter1 = 1
            
            'Reset traversing cell to initial slot of impFilePrefix
            Set currentCell = currentCell.Offset(rowToStartFilling - currentCell.Row, 0)        '9 - 29 = 20
      
            Do While q.Count <= allocatedRows And dwCounter1 <= sviColl.Count
    
                If sviColl(sviCollIndex).impPrefix(impPrefixColl) = impPrefixColl(iMain) Then       'Will use q.Count to space out the dequeues evenly (where applicable)
                    q.Enqueue sviColl(sviCollIndex).sourceVeh()
                End If
                
                sviCollIndex = sviCollIndex + 1
                dwCounter1 = dwCounter1 + 1
            Loop
            
            dwCounter1 = 1
            
            Do While q.Count > 0 And dwCounter1 <= allocatedRows
                
                currentCell.Offset(, sourceVehCell.Column - importFilePrefCell.Column).Value = "'" & q.Dequeue
                'currentCell.HorizontalAlignment = xlLeft       'Issues with 'CreatObject Queue'
                Set currentCell = currentCell.Offset(1, 0)
                dwCounter1 = dwCounter1 + 1
            Loop
            dwCounter1 = 1
            
            q.Clear
            
        Next iMain

    The sheet name is the first listed, ImpSveh. The module is, Module 5.
    Attached Files Attached Files
    Last edited by excelicus; 09-04-2018 at 11:26 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Remove middle name for end of a name string
    By maacmaac in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 08-30-2022, 04:44 PM
  2. [SOLVED] Remove middle names?
    By GHI1968 in forum Excel General
    Replies: 11
    Last Post: 04-06-2018, 03:03 AM
  3. [SOLVED] Remove Middle Name From Cell
    By mrazexcel in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-04-2017, 12:40 AM
  4. clear or remove collection for further using
    By zico8 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-21-2015, 04:22 AM
  5. Remove part of a string before adding to New Collection
    By jordan2322 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-11-2012, 10:03 AM
  6. remove the space in the middle
    By christx in forum Excel General
    Replies: 3
    Last Post: 07-02-2007, 11:06 AM
  7. [SOLVED] Cannot remove item from collection
    By Kou Vang in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-31-2006, 04:25 PM

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