?
Solved

Excel VBA - deleting all objects except graphics

Posted on 2011-09-19
3
Medium Priority
?
380 Views
Last Modified: 2012-06-27
I have a worksheet with buttons and pictures.  The code I tried (below) deletes all shapes but I want to ONLY delete buttons (NOT the pictures).

How can I delete only buttons?

            iCount = ActiveSheet.Shapes.Count
            For i = iCount To 1 Step -1
                ActiveSheet.Shapes(i).Delete
            Next i

0
Comment
Question by:AndresHernando
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 1400 total points
ID: 36558610
Which kind of buttons are they? Forms or ActiveX?
If Forms:
 iCount = ActiveSheet.Buttons.Count
            For i = iCount To 1 Step -1
                ActiveSheet.Buttons(i).Delete
            Next i

Open in new window

0
 
LVL 15

Assisted Solution

by:Haris Djulic
Haris Djulic earned 600 total points
ID: 36558639
if they are all named CommandButton you can use this

        iCount = ActiveSheet.Shapes.Count
            For i = iCount To 1 Step -1
if Mid(ActiveSheet.Shapes(i).Name, 1, 7) <> "Command" then
                ActiveSheet.Shapes(i).Delete
end if

            Next i
0
 

Author Comment

by:AndresHernando
ID: 36559286
rorya, thanks for your help (again).  Works perfectly.

Sam, thanks for your input.  Your solution adds value.  I can see where I can use this. Thanks!

I'll split points 350/150.  I hope that's OK.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question