|
-
Dec 20th, 2015, 05:43 AM
#1
Thread Starter
New Member
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 :-/
-
Dec 20th, 2015, 06:21 AM
#2
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 20th, 2015, 06:51 AM
#3
Thread Starter
New Member
Re: Selecting all shapes in a range in Excel (VBA)
 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?
-
Dec 20th, 2015, 09:28 AM
#4
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
-
Dec 20th, 2015, 10:37 AM
#5
Thread Starter
New Member
Re: Selecting all shapes in a range in Excel (VBA)
 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!!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|