Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Excel VBA - deleting all objects except graphics

Posted on 2011-09-19
3
Medium Priority
?
382 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

604 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