Error 424 : Object Required (when passing a Range as an argument to a Sub)

AOB

Well-known Member
Joined
Dec 15, 2010
Messages
669
Office Version
  1. 365
  2. 2016
  3. 2013
Platform
  1. Windows
I have a function - more accurately, a subroutine - to "cleanse" a value in a table (ListObject) after it has been updated by a user (basically, applies certain restrictions that are too complex to do via native Data Validation)

The sub takes, as argument, a Range, and applies any necessary changes directly to the Value before returning.

VBA Code:
Private Sub CleanseColumnXEntry(rngColumnX As Range)
....
End Sub


The sub is called from a Worksheet_Change event, which handles any/all handling on the sheet by checking which cell has just been changed and performing whatever tasks need to be performed. The cell is identified by a simple Intersect between the EntireRow of the Target range (horizontal) and the DataBodyRange of the ListColumn (vertical)

VBA Code:
Public lcoColumnX As ListColumn

Private Sub Worksheet_Change(ByVal Target As Range)

    On Error GoTo ErrorHandler
   
    Select Case Target.Column
        Case lcoColumnX.Range.Column
            CleanseColumnXEntry (Intersect(Target.EntireRow, lcoColumnX.DataBodyRange))
            ....

End Sub


I'm getting an Error 424 : Object Required when it hits the line where it calls the sub - but when I debug it, all the variables are exactly as expected? Intersect(Target.EntireRow, lcoColumnX.DataBodyRange) evaluates to exactly the cell/range I want to run the sub against, it is showing as an Object/Range in the watch window, it has the correct address, everything.

To clarify - if I put a breakpoint at the line where it (is supposed to) call the sub, and add the watch : TypeName(Intersect(Target.EntireRow, lcoColumnX.DataBodyRange)) - it shows as "Range"? So - before I call the sub, the argument I'm passing is definitely a Range object, and that's the only parameter for the sub - so what "object" is required other than the one I'm passing to the sub, which for all I can see, is present and correct?
 
Last edited:

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Problem solved by removing the parentheses around the parameter... 🤦‍♂️

VBA Code:
CleanseColumnXEntry Intersect(Target.EntireRow, lcoColumnX.DataBodyRange)
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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