Hi,
I have created the following function in excel
Public Function Main_HideRows(ByVal rng As Range, tgbtn As ToggleButton)
Dim sht As Excel.Worksheet
Dim c As Integer
Dim c2 As Integer
Set sht = Sheet19
Set c2 = 32000
Application.ScreenUpdating = False
' this hides the rows for the range
If tgbtn.Value = False Then
Debug.Print tgbtn.Value
tgbtn.Caption = "Show Detail"
For c = 1 To sht.Range("rng").Rows.Count
If sht.Range("rng").Cells(c, 1).Value = sht.Range("rng").Cells(c, 2).Value = "Visible" Then
sht.Range("rng").Columns(c).Hidden = False
If c < c2 Then
c2 = c
End If
Else
sht.Range("rng").Rows(c).Hidden = True
End If
Next
Application.ScreenUpdating = True
Else
Debug.Print tgbtn.Value
Application.ScreenUpdating = False
' this shows the rows for the range
For c = 1 To sht.Range("rng").Rows.Count
If sht.Range("rng").Cells(c, 1).Value = sht.Range("rng").Cells(c, 2).Value = "Visible" Then
sht.Range("rng").Columns(c).Hidden = Truee
If c < c2 Then
c2 = c
End If
Else
sht.Range("rng").Rows(c).Hidden = False
End If
Next
Application.ScreenUpdating = True
tgbtn.Caption = "Hide Detail"
End If
End Function
I then use the following to call it when the toggle button is clicked
Private Sub tgbtnSeasonal_Click()
Call Main_HideRows(ra_main_seasonals, tgbtnSeasonal)
End Sub
However, I get the 424 error saying that an object is required.
What is the reason behind this ?
Thanks
Bilal
Bookmarks