Thursday, 12 September 2013

Dim as Control in VBA Excel

Dim as Control in VBA Excel

I'm trying to go over check boxes in a user form and display them in a
pivot table according to the user selection
I use the following code:
Dim mthIdx As Long
Dim nm As String
Dim c As Control
With ActiveSheet.PivotTables(CakePivot2).PivotFields("month")
For mthIdx = 1 To 12
nm = "CheckBox" & mthIdx
Set c = Controls(nm)
.PivotItems(mthIdx).Visible = printing_rep.c.Value
Next
End With
It works fine when I put it in a user form privete sub but if I'm trying
to put it in a different module I get "Sub or function not defined" error
and "Controls" is highlighted in the code. Does anyone knows what am I
doing wrong?

No comments:

Post a Comment