Solved

Excel VBA - deleting all objects except graphics

Posted on 2011-09-19
3
379 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 350 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 150 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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,…
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

707 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