I'm writing a macro that along other things formats a bunch of much sheets, one subroutine I've written needs to accept a worksheet object I've defined and used earlier. When i try and call the subroutine with the worksheet object as a parameter i get an "object doesn't not support this property or method"
Option Explicit
Public wb As Workbook
Public data, summary_month, summary_item, summary_charge, summary_pro As Worksheet
Public i, n, x, y, z As Variant
Public libName(), itype(), tcharge(), tprofile() As Variant
Public profile, pay_lib, item_auth, total_paid, month, item_type, chr_type As Variant
Public Sub main()
Set wb = ThisWorkbook
Set data = wb.Sheets(1)
Set summary_month = wb.Sheets(2)
Set summary_item = wb.Sheets(3)
Set summary_charge = wb.Sheets(4)
Set summary_pro = wb.Sheets(5)
With data
Set pay_lib = .Range( _
.Cells(2, 2), _
.Cells(2, 2).End(xlDown))
Set item_auth = .Range( _
.Cells(2, 4), _
.Cells(2, 4).End(xlDown))
Set month = .Range( _
.Cells(2, 3), _
.Cells(2, 3).End(xlDown))
Set total_paid = .Range( _
.Cells(2, 10), _
.Cells(2, 10).End(xlDown))
Set item_type = .Range( _
.Cells(2, 5), _
.Cells(2, 5).End(xlDown))
Set chr_type = .Range( _
.Cells(2, 6), _
.Cells(2, 6).End(xlDown))
Set profile = .Range( _
.Cells(2, 8), _
.Cells(2, 8).End(xlDown))
End With
'''''''''''''''''''''''''''''''''''''''''''''
''''''''''some other stuff'''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''
change_colors (summary_month)
End Sub
Sub change_colors(wksheet As Worksheet)
With wksheet
For Each i In .Range(.Cells(2, 1), .Cells(2, 1).End(xlDown))
If i.Row Mod 2 = 0 Then
.Range(.Cells(i.Row, i.Column), .Cells(i.Row, i.Column).End(xlToRight)).Interior.ColorIndex = 31
Else
.Range(.Cells(i.Row, i.Column), .Cells(i.Row, i.Column).End(xlToRight)).Interior.ColorIndex = 2
End If
Next i
End With
when the subroutine is called the 'with' statement should alternate colors based on row, and from my testing there doesn't seem to be anything round with that, i get the error when the subroutine is being called. both subs are in the same module.
Clearly there is something i'm not fully understanding with how worksheet objects work any help would be greatly appreciated