Help with run-time error 424, custom class method

cbrf23

Board Regular
Joined
Jun 20, 2011
Messages
241
Hi, I'm having a go at trying to use classes.

Can anyone help me figure out what I did wrong here?

I defined a class (ClaFeature) and first I wrote a subroutine in a standard module which defined certained values of the class. Everything worked great.
Code:
Sub testClass()
Dim rngItem                 As Range
Dim BPFeature               As ClaFeature
 
Set rngItem = Intersect(Range("A:A"), Selection.Rows.EntireRow)
    If Not rngItem.Value = Empty Then
        Set BPFeature = New ClaFeature
        With BPFeature
            .Item = rngItem.Value
            .InputDescription = rngItem.Offset(0, 1).Value
            .Nominal = rngItem.Offset(0, 2).Value
            .HighTolerance = rngItem.Offset(0, 3).Value
            .LowTolerance = rngItem.Offset(0, 4).Value
            .Method = rngItem.Offset(0, 5).Value
            .Zone = rngItem.Offset(0, 6).Value
                If ThisWorkbook.Sheets("INPUT").Range("H2").Value = "METRIC" Then
                    .Metric = True
                Else
                    .Metric = False
                End If
        End With
    End If
End Sub

Then I decided that I would be better served if I modified that subroutine and put it in the class module so I could use it as a method for that class:
Code:
Sub Define(rngTarget As Range)
       With Me
            .Item = rngTarget.Value
            .InputDescription = rngTarget.Offset(0, 1).Value
            .Nominal = rngTarget.Offset(0, 2).Value
            .HighTolerance = rngTarget.Offset(0, 3).Value
            .LowTolerance = rngTarget.Offset(0, 4).Value
            .Method = rngTarget.Offset(0, 5).Value
            .Zone = rngTarget.Offset(0, 6).Value
                If ThisWorkbook.Sheets("INPUT").Range("H2").Value = "METRIC" Then
                    .Metric = True
                Else
                    .Metric = False
                End If
        End With
End Sub

I then wrote a sub in a standard module to test using the method, and when I step through, I'm getting a run-time error 424 object required.
The line thats highlighted is BPFeature.Define (rngItem)
Code:
Sub testDefine()
Dim rngItem                 As Range
Dim BPFeature               As ClaFeature
 
Set rngItem = Intersect(Range("A:A"), ActiveCell.Rows.EntireRow)
    If Not rngItem.Value = Empty Then
        Set BPFeature = New ClaFeature
        BPFeature.Define (rngItem) '<------error here
    End If
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
When you put the argument in parentheses, it tries to pass a variant array instead of a range.

Code:
BPFeature.Define rngItem
 
Upvote 0
Wow, thanks shg. That seems kind of odd. I've always passed an argument to a function or another subroutine in parentheses like that.

Anyways, thanks!

Out of curiousity, what would you want to pass a variant array for?

Would it be if I were building a collection or something and could use it to define a bunch of bpfeatures?
Code:
        Set BPFeature (i) = New ClaFeature
        BPFeature.Define rngItem (i)
    End If
End Sub
or something like that...
 
Last edited:
Upvote 0
I don't know that this is exhaustive, but generally,

Code:
' parens required:
    Call MySub(arg)
    myResult = MyFunc(arg)
 
' pass arg ByVal or ByReg as dictated by procedure signature:
    MySub arg
    MyFunc arg
 
' pass arg ByVal irrespective of procedure signature,
' which won't work for a procedure expecting an object:
    Call MySub((arg))
    myResult = MyFunc((arg))
    MySub (arg)
    MyFunc (arg)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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