Passing objects as parameters in Excel VBA
excel, vba
Solution
select_cells (r) 'this doesn't work
You can't use parentheses to pass object parameters to a procedure. Just do this:
select_cells r
The archaic, obsolete `Call` keyword can be used, if you really want to keep the parentheses.
Problem
How do I pass an object to a private sub as a reference in Excel VBA? Below is what I am trying to do: ``` Sub main() Dim r As Range Set r = Sheets("Sheet1").Range(Cells(1, 1), Cells(27, 27)) r.Select 'this works select_cells (r) 'this doesn't work End Sub Private Sub select_cells(a As Range) a.Select 'prompts Object Required error End Sub ```