Selecting all shapes in a range in Excel (VBA)
I need all shapes within certain columns to dissapear/apear upon the click of a button. (Because shapes can be moved to other columns I do not want to specify the shapes in my code)
Hiding/showing all shapes on the sheet I can do (cf. code below), but not for a specific range.
Dim Sh as Shape
With ActiveSheet
For Each Sh In ActiveSheet.Shapes
If Sh.Type = msoGroup Then 'only grouped shapes need to appear/dissapear
Sh.Visible = msoTrue '/msoFalse
End If
Next Sh
End With
I've searched all over google for possible solutions, but don't find anything :-/
Re: Selecting all shapes in a range in Excel (VBA)
you can try like
Code:
Set s = ActiveSheet
On Error Resume Next
For Each Sh In s.Shapes
If Sh.GroupItems.Count > 1 Then
If Err.Number = 0 Then Sh.Visible = Not Sh.Visible
Err.Clear
End If
Next
on error goto 0
Re: Selecting all shapes in a range in Excel (VBA)
Quote:
Originally Posted by
westconn1
you can try like
Code:
Set s = ActiveSheet
On Error Resume Next
For Each Sh In s.Shapes
If Sh.GroupItems.Count > 1 Then
If Err.Number = 0 Then Sh.Visible = Not Sh.Visible
Err.Clear
End If
Next
on error goto 0
But how to do this for only shapes in specific columns? Let's say, shapes located in E:G?
Re: Selecting all shapes in a range in Excel (VBA)
I think this would work:
Code:
If sh.TopLeftCell.Column > 4 And sh.TopLeftCell.Column < 8 Then
'do something
End If
Re: Selecting all shapes in a range in Excel (VBA)
Quote:
Originally Posted by
vbfbryce
I think this would work:
Code:
If sh.TopLeftCell.Column > 4 And sh.TopLeftCell.Column < 8 Then
'do something
End If
Super, that worked!
Thanks a lot!!