Automation Error when building collection

bbrother

New Member
Joined
Nov 23, 2015
Messages
36
Dear Excel Experts,

I have a simple piece of VBA code with some (messy) error handling that builds a collection by constructing a string and seeing if it exists in a larger collection.

This code generates an application execution error on the second pass through the for next loop.

Code:
Private Sub UserForm_Initialize()
    Dim i As Long
    Dim Product As String
    Dim PCores As Collection
    
    If MyTools.PLProducts.count = 0 Then Call ConfiguratorMain.DataLoader
    
Resum:
    ConfidentialL.Caption = ConfiguratorMain.ConfidentialL.Caption
    OutputLB.ColumnCount = 4
    OutputLB.TextAlign = fmTextAlignRight
    
    Set PCores = New Collection
    On Error GoTo eh  'If the constructed product name doesn't exist in the collection, then skip
    For i = 1 To 2 ^ 16
        Product = "5TB-XFD-" & i
        If MyTools.PLProducts(Product) Then
            PCores.Add i
        End If
eh:
    Next
    On Error GoTo 0


End Sub
 

bbrother

New Member
Joined
Nov 23, 2015
Messages
36
Maybe....
Code:
PCores.Add Product
HTH, Dave
Nope, it's really more convenient for me to have a number I can calculate with. That integer represents number of CPU cores for which I need to use for various calculations. Are you saying that using a collection of strings rather than a collection of Longs will avoid the error?
 

NdNoviceHlp

Well-known Member
Joined
Nov 9, 2002
Messages
2,346
No, I was just guessing that you were trying to make a new collection of products from the MyTools.PLProducts collection. That doesn't really explain the error. Maybe...
Code:
Product = "5TB-XFD-" & CSTR(I)
Why 2 to the power of 16? You could take the error code out and insert some msgboxes to find out where and what is actually causing the error. HTH. Dave
 

Forum statistics

Threads
1,081,976
Messages
5,362,511
Members
400,678
Latest member
alecalec202

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top