Results 1 to 3 of 3

Thread: [RESOLVED] (Excel VBA) Run-time error 424: Object required for a collection

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2016
    Posts
    2

    Resolved [RESOLVED] (Excel VBA) Run-time error 424: Object required for a collection

    Hi all, first post so forgive me if I get this wrong. I keep getting a run-time error 424 when trying to debug.print a previously defined collection and I am not sure why. Following is the current code.

    Code:
    Sub QuoteArr()
    
        Dim sh As Worksheet, sh2 As Worksheet
        Dim arrQuote() As String, arrParent() As String, arrOffer() As String, arrPrdMdl() As String
        Dim lLastRow As Integer, lLstRw2 As Integer
        Dim collQuote As New Collection
        Dim c As Range, rng As Range
        Dim i As Integer, j As Integer, k As Integer
            
        Set sh = ThisWorkbook.Worksheets("Sheet1")
        Set sh2 = ThisWorkbook.Worksheets("Sheet2")
        Set rng = sh2.Range("a1").CurrentRegion
    
    ' Get last row with text by searching from the bottom of the worksheet
        lLastRow = sh.Cells(sh.Rows.count, 1).End(xlUp).Row
        lLstRw2 = sh2.Cells(sh2.Rows.count, 1).End(xlUp).Row
    ' Print the row number
        Debug.Print lLastRow
        Debug.Print lLstRw2
    
    With sh2
        For Each c In rng
            collQuote.Add c.Value
        Next
    '    Debug.Print collQuote.count
    '    For j = 1 To collQuote.count
    '        Debug.Print collQuote(j)
    '    Next j
    End With
    '    Debug.Print collQuote.count
    '    For j = 1 To collQuote.count
    '        Debug.Print collQuote(j)
    '    Next j
    With sh
    ReDim arrQuote(1 To lLastRow), arrParent(1 To lLastRow), arrOffer(1 To lLastRow), arrPrdMdl(1 To lLastRow)
        For i = 1 To lLastRow
            arrQuote(i) = .Cells(i, 1)
            arrPrdMdl(i) = .Cells(i, 9)
            arrParent(i) = .Cells(i, 20)
            arrOffer(i) = .Cells(i, 21)
        Next i
    '    Debug.Print "Quote"
    '    For i = LBound(arrQuote) To UBound(arrQuote)
    '        Debug.Print arrQuote(i)
    '    Next i
    End With
    
    'to access the collection
        For k = 2 To collQuote.count
            Debug.Print collQuote(k).Name 'this is where the error occurs
        Next k
        
    End Sub
    Attached is the workbook and thanks for taking a look at this.
    Attached Files Attached Files

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width