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
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
Through formatting the cells, you can make your Excel data more beautiful and easier to understand. If you record a macro to add borders to Excel range, you will notice that it generates 30 plus lines of code for just a small work. Here we are sharing one line of code which does the same thing.
Here is one more wonderful free tool from ExcelSirJi.com which makes your life easy. Time & Motion Tracker helps you to track Start and End time of any type of transaction or activity. The good thing is, it is VBA based tool which helps you to protect from manual manipulation in the data by the user. It is also easy to use, just click on Start (shortcut: Ctrl+Shift+A) or Stop (Ctrl+Shft+S) buttons to record the time
VBA Code to Count Color Cells With Conditional Formatting Have you ever got into situation in office where you need to count the cells with specific color in conditional formatted Excel sheet? If yes then…
WEEKDAY function applies to a Date and returns the output for Day of the week. The output of the function varies from 0 to 7
https://youtu.be/c2CtJ1uaXSQ Microsoft Excel is a popular spreadsheet application widely used for data analysis and management. One of the essential skills for working with filter data in Power Query in Excel. Filtering allows you to focus…
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…