Object required, runtime error 424, dictionary print to immediate

Certified

Board Regular
Joined
Jan 24, 2012
Messages
189
When I try to print items to an immediate screen and I get an onject required error.

This code is modified from a code I got online.

The debug higlights the line in red.

Code:
Sub Herewegoagain()

    Dim mainDict As New Dictionary, unique1051Dict As New Dictionary
    Dim gemdata As Class1
    Dim rg As Range
    Dim i As Integer
    
    Sheet1.Activate
    
    Set rg = Sheet1.Range("a2").CurrentRegion
    
    For i = 2 To rg.Rows.Count
    
        Set gemdata = New Class1
        
        gemdata.geM = rg.Cells(i, 2)
        gemdata.entitY = rg.Cells(i, 3)
        gemdata.parenT = rg.Cells(i, 5)
        gemdata.parentName = rg.Cells(i, 6)
        gemdata.bU = rg.Cells(i, 7)
        gemdata.pcT = Round(rg.Cells(i, 8), 0)
        gemdata.owneR = rg.Cells(i, 9)
        
            If Cells(i, 5) = "" Then
            
                gemdata.uKey = Cells(i, 2) & Cells(i, 6)
            
            Else
            
                gemdata.uKey = Cells(i, 2) & Cells(i, 5)
            
            End If
        
        mainDict.Add gemdata.uKey, gemdata
        
            If gemdata.owneR = "Company" Then
            
                unique1051Dict(gemdata.geM) = unique1051Dict(gemdata.geM) + gemdata.pcT
            
            End If
    
    Next i
    
    
    printexamplE unique1051Dict


End Sub

Sub printexamplE(unique1051Dict As Dictionary)
  
    Dim key As Variant, gemdata As Class1
    
    Set gemdata = New Class1
    
        For Each key In unique1051Dict.Keys
        
            [COLOR=#ff0000]Set gemdata = unique1051Dict(key)[/COLOR]
        
            Debug.Print gemdata.geM, gemdata.pcT
        
        Next key

End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I'm not clear what you're trying to do here. but, given:

Code:
Dim gemdata As Class1
'...
Set gemdata = unique1051Dict(key)

it looks like you are expecting unique1051Dict to contain Class1 objects?

However, the only code line where you put anything in to unique1051Dict is here:

Code:
unique1051Dict(gemdata.geM) = unique1051Dict(gemdata.geM) + gemdata.pcT

Although gemdata is Class1, this line simply adds whatever is in gemdata.pcT to the gemdata.geM element in your Dictionary. So your dictionary will contain values, not Class1 objects.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top