Stuart1044
Stuart1044

Reputation: 444

Passing Worksheet To Sub Routine

I am trying to call a sub routine by passing a certain sheetname as the parameter, but I receive the following error:

Object doesn't support this property or method

Here is my code:

Public Sub PerformanceLeague()

Dim wsPerformanceLeague As Worksheet

Set wsPerformanceLeague = Worksheets("PerformanceLeague")
SetHeadings wsPerformanceLeague

End Sub

Public Sub SetHeadings(sSheet As Worksheet)

Dim headers() As Variant
Dim ws As Worksheet
Dim wb As Workbook

Application.ScreenUpdating = False

End Sub

I have tried calling the sub routine as below as well, but receive the same error:

Call SetHeadings(wsPerformanceLeague)

Upvotes: 2

Views: 595

Answers (1)

Siddharth Rout
Siddharth Rout

Reputation: 149315

  1. Declare wsPerformanceLeague as worksheet. Dim wsPerformanceLeague as Worksheet

  2. Change wsPerformanceLeague = Worksheets("PerformanceLeague") to Set wsPerformanceLeague = Worksheets("PerformanceLeague")

You have to use the word Set

Upvotes: 3

Related Questions