Trying to iterate (for each...next) through specific shape types (form controls, not activex) in a shape group ("grpNav"). Can't get it to work, and the MSDN article is somewhat vague on syntax. What am I doing wrong?
Code:
Function Nav(Optional Source As Worksheet) As Range
'decs
Dim ShapeName As String
Dim rTarget As Range
Dim rb As OptionButton
Dim cb As CheckBox
'defs
On Error GoTo errFatal
fn "Nav"
If Source Is Nothing Then Set Source = ActiveSheet
dp "Source set to: " & Source.Name
ToggleEvents False
'main
On Error GoTo errView
For Each rb In Source.Shapes("grpNav").GroupItems
ShapeName = Replace(opt.Name, "rb", "") & "."
With Source
For Each cb In Source.Shapes("grpNav").GroupItems
Set rTarget = Nothing
Select Case UCase(cb.Name)
Case "CHKTOTALCOST": Set rTarget = Application.Union(IIf(rTarget Is Nothing, .Range(ShapeName & ".Cost.Subtotal"), rTarget), .Range(ShapeName & ".Cost.Subtotal"))
Case "CHKUNITCOST": Set rTarget = Application.Union(IIf(rTarget Is Nothing, .Range(ShapeName & ".Cost.Unit"), rTarget), .Range(ShapeName & ".Cost.Unit"))
Case "CHKTOTALHOURS": Set rTarget = Application.Union(IIf(rTarget Is Nothing, .Range(ShapeName & ".Hours.Subtotal"), rTarget), .Range(ShapeName & ".Hours.Subtotal"))
Case "CHKUNITHOURS": Set rTarget = Application.Union( _
IIf(rTarget Is Nothing, .Range(ShapeName & ".Hours.ST.Unit"), rTarget), _
.Range(ShapeName & ".Hours.ST.Unit"), _
.Range(ShapeName & ".Hours.OT.Unit"), _
.Range(ShapeName & ".Hours.DT.Unit"), _
.Range(ShapeName & ".Hours.Difficulty"))
Case Else: dp "Error: " & cb.Name & " unsupported. Resuming"
End Select
rTarget.Hidden = Not (rTarget.Hidden)
skip: Next cb
End With
Next rb
GoTo quit
errView:
dp "Error: Error intersecting view with category. Resuming"
Resume skip
errFatal:
dp "** Error: Unhandled. Terminating"
GoTo quit
quit:
ToggleEvents True
fn "Nav", True
End Function