I have a very basic question about VBA sub routines. What I’m trying to do is
- Set activeCell to Range variable
- Pass that variable to Sub routine
- Do something with the activeCell
What I tried to do is
Sub myMacro() Dim myCell As Range Set myCell = ActiveCell mySub(myCell) End Sub Sub mySub(cell As Range) ' Do something End Sub
I keep getting an “Object required” error.
What is the problem here?
When you pass arguments to a function, you dont need to use parenthesis. Eg:
You could also use Lance sugention and use use
Call AND parenthesis. (Press F1 over
Call in the VBA Editor to get more info about it)
Either way is correct, but the first notation might prove more helpful while learning VBA as the great mojority of Answers in forums use the first one.
You need to use the Call statement on the subroutine.