Object Mandatory Excel VBA Error

I am creating a VBA application and I have the following code:


Dim previousCell As range


Private Sub Worksheet_SelectionChange(ByVal target As range)

Application.EnableEvents = False
On Error GoTo ws_exit:


Set previousCell = target
getEffort (previousCell) '**Here i get object required** 

ws_exit:
    Application.EnableEvents = True
    MsgBox Err.Description

End Sub

Private Function getEffort(ByVal cell As range)

' do soemthing

End Sub

I'm not sure why I'm getting an error message: Object required error at getEffort(previousCell). If I turn in Target, it works.

thank

+5
source share
3 answers

Like others, the problem is in parentheses. What no one explained explains why these are parentheses.

When you say this:

getEffort previousCell

Then you pass the previousCell Range object to the getEffort procedure. This is what the procedure expects, and therefore it is happy.

When you say this:

getEffort (previousCell)

previousCell VBA previousCell. VBA , . Range .Value, .

, getEffort. , getEffort Range, .

, Target previousCell, - . , , previousCell. , :

getEffort (Target)

.

+18

, ​​ , . , () . = -, exec.

previouscell = ActiveCell

0

: -, () - getEffort . , , sub/, . , ?

Dim previousCell As range


Private Sub Worksheet_SelectionChange(ByVal target As range)

Application.EnableEvents = False
On Error GoTo ws_exit:


Set previousCell = target
getEffort previousCell '**Here i get object required** 
'or...
call getEffort(previousCell)

'add this too..
'exit sub
ws_exit:
    Application.EnableEvents = True
    MsgBox Err.Description

End Sub

Private sub getEffort(ByVal cell As range)

' do soemthing

End sub

, , . Exit Sub , .

0
source

All Articles