Here is a VBA code which deletes all the shapes from an Excel sheet. Code is simple but you have to be bit careful while using this code as it deletes all the Shapes, Smart Shapes, Charts, Pictures, Objects and Equations from the sheet
'Following function deletes all the Shapes, Smart Shapes, Charts,
'Pictures, Objects and Equations from the Excel worksheet
Sub DeleteShapesFromSheet()
'Declare variable
Dim objShape As Shape
'Loop through all the shapes from sheet1 and delete
For Each objShape In Sheet1.Shapes
objShape.Delete
Next
End Sub
1. Open an Excel file
2. Press Alt+F11
3. Insert a Module (Insert>Module) from menu bar
4. Paste the code in the module
5. Click on ‘View Macros’ option available under View>Macros ribbon
6. Select ‘DeleteShapesFromSheet’ and click on Run
In most cases, you will want to exclude certain shape types from being deleted within your code. Most commonly, you may not want to remove cell comments or charts as (believe it or not) they are considered shapes! You can add an IF statement to test each shape’s type before deleting it in your loop. The following code shows how you can write your VBA:
Sub DeleteAllShapes()
'PURPOSE: Remove All Shape Objects From The Active Worksheet (Excludes Charts/Comments)
'SOURCE: www.TheExcelsirji.com/the-code-vault
Dim shp As Shape
For Each shp In ActiveSheet.Shapes
If shp.Type <> msoChart And shp.Type <> msoComment Then shp.Delete
Next shp
End Sub
Have you ever felt that Microsoft should have added a formula in Excel which can count the cells based on specific color? I have seen many code requests to share a VBA code that can count the cells by its color. To help our subscribers and developers, we are sharing 2 codes that be used to count the cells with specific color and returns the count of the matching color cells.
VBA Code to Browse a Folder Quite often a VBA developer requires code to browse a folder. This is mainly for saving the output file or reading the input file(s). Below is the VBA code…
Custom Calendar Control for MS Access MS Access by default provides inbuilt functionality to pick dates using calendar control; however it lacks few basic functionalities which makes selecting a date bit difficult. For example, if…
In this guide, you will learn how to use the NPV function in Excel to calculate the net present value of an investment and how to avoid common mistakes when using NPV in Excel.
How to use VBA to open Workbook in Excel? There are few VBA codes which are commonly used by every developer. One of them is giving an option to user to browse a file. Below is a…
The tutorial teaches you the basics of regression analysis and shows a few ways to do linear regression in Excel.
Imagine this: you have a lot of data and need to predict next year’s sales for your company. You’ve found many factors that could affect the sales, maybe even hundreds. But how do you know which ones really matter? You can use regression analysis in Excel. It will help answer this and other questions, like: Which factors are important and which ones don’t matter? How connected are these factors? And how confident can you be in your predictions?”