There are severla errors in your code
Unqualified range references refer to the ActiveSheet. So
Set r = Sheets("Sheet1").Range(Cells(1, 1), Cells(27, 27))
will error if Sheet1 is not active.
r.Select will error if Sheet1 is not active.
select_cells (r) with the brackets is incorrect. Use
select_cells r
a.Select in the Private Sub will error if Sheet1 is not active.
Here's an modified version
Sub main()
Dim r As Range
With Sheets("Sheet1")
Set r = .Range(.Cells(1, 1), .Cells(27, 27))
End With
Debug.Print r.Address ' for diagnostic purposes
select_cells r
End Sub
Private Sub select_cells(a As Range)
' Activate the worksheet first, so you can select a range on it
a.Worksheet.Select
a.Select
End Sub
Note on bracketed parameters
When a Sub or Function parameter is a non-object variable, bracketing the parameter overrides the ByRef/ByVal definition and passes the parameter ByVal
When a Sub or Function parameter is an object variable, bracketing the parameter causes an the default property to be passed to the Sub/Function. In the case of the OP, this is r.Value, which causes a type missmatch.
callin front ofselect_cells:call select_cells (r)worked for me on a local test